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.

I have a working apache vhost such as

<VirtualHost localhost:10006>
    DocumentRoot "/home/pate/***/git/kohana_site/public/site/"
</VirtualHost>

<VirtualHost *:10006>
    ServerName api.*
    DocumentRoot "/home/pate/***/git/kohana_site/public/api/"
    LogLevel debug
</VirtualHost>

If i point to localhost:10006 I get my website and api.localhost:10006 I get my api.

Then I have haproxy setup on top of that, that runs on port 10010 and both localhost:10010 and api.localhost:10010 have the expected behaviour.

Now I have nginx setup on port 80 with this configuration.

server {

    listen  10000;
    server_name api.*;

    location / {
        proxy_pass http://legacy_server;
    }

}

server {
    listen                  10000 default;
    server_name             _;

    location /nginx_status {
        stub_status  on;
        access_log   off;
    }

    # images are accessed via the CDN over HTTP (not https)

    location /n/image {
        proxy_pass http://image_caching_server;
    }

    location / {
        return 301 https://$host:10014$request_uri;
    }
}

upstream legacy_server {

    server localhost:10010 fail_timeout=0;

}

the problem is that apache does not recognize the vhost properly and redirects api.localhost to the website instead of the api.

I tried playing with set_proxy_header Host $host but it doesn't seem to do anything.

share|improve this question
add comment

1 Answer

Can you try to add those tags to the location block:

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

restart nginx and try if it works

share|improve this answer
    
I tried it but no luck! –  Paté Nov 6 '12 at 22:58
    
can you paste in pastebin.com your final config? –  Hex Nov 6 '12 at 23:10
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.