How to setup apache to catch a proxy_pass from nginx?

Posted by Paté on Server Fault See other posts from Server Fault or by Paté
Published on 2012-11-06T22:02:15Z Indexed on 2012/11/06 23:03 UTC
Read the original article Hit count: 177

Filed under:
|

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.

© Server Fault or respective owner

Related posts about apache2

Related posts about nginx