nGinX HTTP-Code 200 / 404

Maxim Dounin mdounin at mdounin.ru
Tue Jan 10 10:25:04 UTC 2012


Hello!

On Tue, Jan 10, 2012 at 09:42:45AM +0100, Maik Unger wrote:

> Hy,
> 
> We have that problem, that a site is not reachable throught nginx with
> the domain name (for example www.foobar.org), even the websites are
> reachable without nginx directly to apache.
> 
> This problem is not time specific, so that we have no solution at this
> moment.
> 
> What is the problem here?

Most likely you are using wrong config.

By default nginx will use hostname as specified in proxy_pass 
directive, i.e.

    proxy_pass http://127.0.0.1:8080;

will generate request with Host header set to "127.0.0.1:8080", 
not to "www.foobar.org".  Your backend server won't recognize it 
if it's configured to serve many virtual hosts, and 
"www.foobar.org" is just one of them.

To preserve the hostname from the original request (as sent to 
nginx server), use 

    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;

Maxim Dounin



More information about the nginx mailing list