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.

My setup is basically this: I have pointed two domains at my VPS running Ubuntu 10.04. I am using an nginx frontend and Apache running Django with mod-wsgi (not an issue, it works fine).

Nginx is proxying just fine and Apache does its job, but all requests are picked up by the first Virtualhost, even if the server_name is not supposed to match. So domain1.com and domain2.com are both giving me the same webpage. Grateful for any ideas/answers! If anything needs to be clarified, please let me know.

nginx server conf

server {
     listen  80  default;
     server_name domain1.com;

     location / {
         proxy_pass http://localhost:8001;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
     listen  80;
     server_name domain2.com;

     location / {
         proxy_pass http://localhost:8001;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

And the Apache conf:

NameVirtualHost *:8001

<VirtualHost *:8001>
    ServerAdmin webmaster@localhost
    ServerName domain1.com
    ServerAlias www.domain1.com
    ...
</VirtualHost>

<VirtualHost *:8001>
    ServerAdmin webmaster@localhost
    ServerName domain2.com
    ServerAlias www.domain2.com
    ...
</VirtualHost>
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

CMIIW,

i think you must pass the Host header also

    proxy_set_header        Host            $host;

    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
share|improve this answer
    
Accepting this answer because it was correct. After removing and creating a new wordpress it now works. –  Erik Kronberg Oct 22 '10 at 7:51
add comment

Note that the HTTP Host header is not forwarded ...

nginx proxy_pass documentation

share|improve this answer
    
So my best option is having Apache listen to two different ports? Any downsides to that? –  Erik Kronberg Oct 21 '10 at 19:39
    
That would be one way to do it. I don't see any immediate downsides which would not also apply to your present configuration (aside from opening up another port). –  danlefree Oct 21 '10 at 19:54
    
Turns out I really need that original IP passed for wordpress :/ Will keep looking. –  Erik Kronberg Oct 21 '10 at 20:58
add comment

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.