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

I have 2 sites, Main.com and New.com. I switched over from Apache to Nginx in front of it, and it worked well for Main.com, but it seems the Virtualhosts aren't working right, since a request for New1.com just shows the homepage of Main.com. Another thing is that this setup uses Plesk to manage the Virtualhosts at the moment.

netstat -plunt:

tcp        0      0 xxx.xxx.xxx.xxx:8080         0.0.0.0:*                   LISTEN      13198/httpd
tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      13198/httpd
tcp        0      0 :::443                      :::*                        LISTEN      13198/httpd
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      13970/nginx

Nginx default.conf:

 stream apachephp {
     server [::]:8080; #apache 
 }

 server {
     listen       80;
     server_name  main.com .main.com admin.main.com forum.main.com m.main.com;

     #charset koi8-r;
     #access_log  /var/log/nginx/log/host.access.log  main;
     access_log /var/www/vhosts/main.com/logs/nginx_access.log;
     error_log /var/www/vhosts/main.com/logs/nginx_error.log;

     location /media/ {
         #root   /usr/share/nginx/html;
         #index  index.html index.htm;
         root /var/www/vhosts/main.com/html;
     }

     error_page  404              /404.html;

     # redirect server error pages to the static page /50x.html
     #
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
         root   /usr/share/nginx/html;
     }

     # Status for datadog/others
     location /nginx_status {
         stub_status on;
         access_log off;
     }

     # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     #
     location / {
         proxy_pass http://main.com:8080/;
         proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-WTF-Nginx "hi";
     #root /var/www/vhosts/main.com/html;  
     }
  }

Virtualhosts worked fine before this change. I think I'm sending the Host header properly. The proxy_pass currently does send to main.com. When I set it to either 127.0.0.1:8080 or serverIP:8080 Apache was rejecting the requests:

2013/01/02 06:29:56 [error] 13112#0: *94 connect() failed (111: Connection refused) while connecting to upstream, 
client: 78.249.185.245, server: main.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "www.main.com"

Apache listens (httpd.conf):

Listen 127.0.0.1:8080
Listen xxx.xxx.xxx.xxx:8080

Everything else seems to be ok, it's just not mapping to the correct vhost in Apache it seems.

Edit: WTF just realised I asked a similar question over a year ago. I think that was solved and was about mapping to only one vhost, and I wasn't dealing with multiple. But I guess the Host header isn't being sent correctly.

Edit2: Dumping $_SERVER, HTTP_HOST = "www.new.com" (correct), but DocumentRoot is set to main.com. I added the correct DocumentRoot to the vhost.conf under new.com, reconfigured domain, but no effect.

Edit3: apachectl -t reports this 5x:

[Wed Jan 02 08:47:21 2013] [warn] VirtualHost 62.255.175.222:8080 overlaps with VirtualHost 62.255.175.222:8080, the first has precedence, perhaps you need a NameVirtualHost directive

Edit4: Enabled NameVirtualHost in httpd.conf (set to xxx.xxx.xxx.xxx:8080) (ie my server IP). Changed nginx.conf proxy_pass http://xxx.xxx.xxx.xxx:8080/, and added DocumentRoot's to all the vhosts. Seems to have sorted itself out for the moment.

share|improve this question
    
Apache doesn't seem to be listening on :: port 8080, but that's what you have specified for apachephp in your nginx configuration. –  Michael Hampton Jan 2 '13 at 16:27

1 Answer 1

Seems that adding DocumentRoot to each VirtualHost, and enabling NameVirtualHost solved it for the most part.

share|improve this answer

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.