Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Runing Windows Server 2008 R2

nginx on port 8080 Apache on port 80

Apache is hosting 5 websites configured within the directive.

I'm trying to configure nginx as proxy in front of Apache, (I'll reverse the port numbers after done testing).

nginx.conf includes this server,

    server {
    listen       8080;
    server_name  www.domain1.com;

    root   PATH/domain1/;
    index  index.html index.htm index.php;
    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
           expires 365d;
        }

    ## send request back to apache1 ##
    location / {
     proxy_pass  http://127.0.0.1;
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}server {
    listen       8080;
    server_name  www.domain2.com;

    root   PATH/domain2/;
    index  index.html index.htm index.php;

    ## send request back to apache1 ##
    location / {
     proxy_pass  http://127.0.0.1;
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header        Host            $host;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

It works, but If I add a second server, the second server will result in 404 error because nginx is still trying to locate the content for the second site within the site1 folder.

What is the proper way to configure multiple websites on nginx? (Windows).

share|improve this question
    
If I add a second server If you post the vhost conf for the second server too, that may help someone to help you! –  Pothi Sep 18 '13 at 1:34
    
Thanks, question updated. –  D_Guy13 Sep 18 '13 at 5:22
add comment

1 Answer 1

first guess: did you restarted/reloaded your nginx after changing the config?

you config looks ok so far; i'd include a separate access_log /path/to/domainX_access.log directive into each server {} - part for better debugging; at least you'll know from the logs, which virtual-host is met.

share|improve this answer
    
Of course, nginx -s reload, I have a main log file, and all requests are being sent to the first server, and there for resulting in error 404, 403 for when trying to load the second server. –  D_Guy13 Sep 18 '13 at 7:05
    
404 -> your root /path/to/files; is not correct or the files are really not there; usually the logs are teling the truth :) –  that guy from over there Sep 18 '13 at 7:10
    
403: no access to files or directories in root /../; path, if not otherwise protected; check your permissions on given path, if the webserver-user can access every level. –  that guy from over there Sep 18 '13 at 7:12
    
ah, windows, dont know how to set the right path ... c:/blah/blieh/blupp? –  that guy from over there Sep 18 '13 at 7:12
    
Wwhat should the path/to/files; be? shouldn't it be the same as Apache's vhosts pathes? –  D_Guy13 Sep 18 '13 at 7:44
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.