Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
server {
    listen       81;
    server_name localhost;

    location /media/ {
        root /var/www/vhosts/;

    error_page  404              /404.html;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;

    location / {
        proxy_set_header Host $host;
        proxy_set_header Connection Close;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        root /var/www/vhosts/;

This is what I have in nginx/defaults.conf. The server is currently using Apache fine, and Plesk, which seems to manage vhosts on its own (somehow).

Any requests to work fine, but uses an incorrect vhost.

I'm not 100% sure how the vhost situation works with Plesk, but it was installed and the default vhost is, and no matter how much fiddling with the proxy settings I do, I can't get it to use the vhost.

edit added a ; to the root line under location. It was missing, I tried adding it but still no luck.

update added ServerName "" to /etc/httpd/conf.d/zz010_psa_httpd.conf. Now under apache-status, it lists the vhost as, but still "uses" Boo.

It also seems that it's using DocumentRoot from the main apache httpd.conf, and not using the proper virtual host.

share|improve this question
up vote 0 down vote accepted

From the nginx docs on proxy_pass:

Note that the HTTP Host header is not forwarded, but is set based on the proxy_pass statement.

This means your proxy_set_header Host $host; line has no effect. The actual Host header passed to Apache will be Host: as per the proxy_pass statement.

I recommend this location / section to proxy as you described:

location / {
    proxy_set_header Connection Close;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
share|improve this answer
Ah, thanks. So far that works. Can't believe I missed that. – paimoe Dec 2 '11 at 7:49
By default, nginx will use the proxy_pass argument for the Host header of the proxied request, but proxy_set_header Host $host; will override the default behavior and pass on the Host header from the original request. The fact that this change is fixing the problem tells me that the vhosts weren't all set up to be available on in apache. – kolbyjack Dec 2 '11 at 12:09
despite the docs specifically saying you can't forward Host? – lunixbochs Dec 2 '11 at 13:39
Despite the docs saying that the default is to use the proxy_pass argument. You can override the default. – kolbyjack Dec 2 '11 at 17:48
have you tested this personally? failed completely last time I tried to do it exactly how you said, as per the part of the docs saying you can't override the Host. – lunixbochs Dec 2 '11 at 20:44

Your Answer


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.