Nginx in front of Apache: Only default server website is shown

Written by - 0 comments

Published on June 18th 2014 - Listed in Linux Internet


Had a weird case, where an Nginx is in front of an Apache web server and whenever I tried to access the website through the Nginx, the Apache's default website was shown instead of the virtual hosts website.

I had the following config in Nginx:

server {
  listen 80;
  server_name vhost.example.com;

  location / {
    include /etc/nginx/proxy.conf;
    proxy_set_header Host $host;
    proxy_pass http://apache:80;
  }
}

The reason for this weird effect is that I already had "proxy_set_header" defined in the included config file proxy.conf. It seems that if it is defined twice, the host name gets lost and therefore Apache in the backend only serves the default server's website.

I have double-checked and verified this with these combinations:

  • Debian Wheezy, Nginx 1.2.1, Apache 2.2.22
  • Ubuntu 14.04, Nginx 1.4.6, Apache 2.4.7

After removing the additional "proxy_set_header" definition, the correct website for vhost.example.com was shown.




Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.