Welcome! Log In Create A New Profile

Advanced

Need Help Moving From Lighttpd To NGINX

Posted by NeHe 
Need Help Moving From Lighttpd To NGINX
August 27, 2012 03:19AM
Running the following sites:

Internally: internal reports, company web page, webmail
Externally: company web page, webmail (SSL)

In lighttpd I was able to use sockets to monitor specific IP / port combinations as follows:

$SERVER["socket"] == "192.168.0.x:80" {
$HTTP["host"] =~ "www.example.com" {
server.document-root = "/usr/local/www/external"
accesslog.filename = log_root + "/access-int-www.log"
}

$HTTP["host"] =~ "internal.example.com" {
server.document-root = "/usr/local/www/internal"
accesslog.filename = log_root + "/access-int-internal.log"
}

$HTTP["host"] == "webmail.example.com" {
server.document-root = "/usr/local/www/roundcube"
accesslog.filename = log_root + "/access-int-webmail.log"
}
}

For external sites I did the same thing but watched for {external IP:port 80 and port 443}

I set up Nginx like so...

server {
listen 192.168.0.x:80;
server_name www.example.com;
root /usr/local/www/external;

...
}

server {
listen 192.168.0.x:80;
server_name internal.example.com;
root /usr/home/www/internal;

...
}

but I've run into some issues.

the page that loads when going to say webmail.example.com could be the last server set up for 192.168.0.x

if I drop the IP I don't seem to have this issues, but then I lose the ability to load webmail.example.com as HTTP while forcing external IP address to use HTTPS.

Also, if a user connects to my site via IP address instead of name... that IP is used for every link clicked and continues to show in the URL bar. This causes issues with external google code that expects the url to have the site name not the IP, is there a way to force the server name to be used vs the IP?

Also with both ports 80 and 443 being used, if I type in an address like https://internal.example.com (there is no internal.example.com on port 443, but there is on port 80) I get an odd error page (444), rather than "page not found". It's like nginx is looking at server names in all configs and saying yep, that name exists, but no ssl version of it.

I know it's a mess of issues, and probably random and chaotic, but I'd really like to get a working confix. What I have no is working, but not the way I want.

in light if the ip was 192.168.0.x and a user connected to webmail it would load roundcube in http.
if the user ip was {external} and the address was http://webmail.example.com, it would redirect to https://webmail.example.com.

I'm sure there has to be an easy solution would love any help that you guys can provide, have no issues sharing my config (all of it) so you have a clear idea what I'm trying to do.

in short I want this:

internal (192.168.0.80):
internal.example.com /usr/local/www/internal
www.example.com /usr/local/www/external
webmail.example.com /usr/local/www/roundcube

external (some static ip:80):
www.example.com /usr/local/www/external
webmail.example.com /usr/local/www/redirect to ssl

external (some static ip:443):
webmail.example.com /usr/local/www/roundcube (ssl)
Re: Need Help Moving From Lighttpd To NGINX
August 27, 2012 04:29AM
To clarify: The wrong page loads only if I use a mix of IP:PORT with just PORT (no ip).

I wanted the mix because there are a few pages that I want to share internally and externally (company page / webmail), but there are also pages I want internal only (internal reports).

using listen 80; to deal with both internal / external is easier than setting up one server for each :(

I think I resolved the connecting to site via an IP address by adding the following to the default server:

if ($host = 'external ip address') {
rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}

Is there a better way to write this? I've read that using if is bad?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 149
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready