# nGinX HTTP-Code 200 / 404

**URL:** <https://www.ruby-forum.com/t/nginx-http-code-200-404/215606>\
**Category:** NGINX\
**Created:** [January 10, 2012, 9:42am UTC](https://www.ruby-forum.com/t/nginx-http-code-200-404/215606 "2012-01-10T09:42:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 10, 2012, 9:42am UTC](https://www.ruby-forum.com/t/nginx-http-code-200-404/215606/1 "2012-01-10T09:42:45Z")

</div>

Hy,

We have that problem, that a site is not reachable throught nginx with  
the domain name (for example [www.foobar.org](http://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?

Best Regards,

Maik U.

---

<div class="post-metadata">

**Author:** ![maikungeriok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@maikungeriok](https://www.ruby-forum.com/u/maikungeriok)\
**Post date:** [January 10, 2012, 11:25am UTC](https://www.ruby-forum.com/t/nginx-http-code-200-404/215606/2 "2012-01-10T11:25:33Z")

</div>

Hello!

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

> Hy,
> 
> We have that problem, that a site is not reachable throught nginx with  
> the domain name (for example [www.foobar.org](http://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](http://www.foobar.org)”. Your backend server won’t recognize it  
if it’s configured to serve many virtual hosts, and  
“[www.foobar.org](http://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 D.

---

<div class="post-metadata">

**Author:** ![maikungeriok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@maikungeriok](https://www.ruby-forum.com/u/maikungeriok)\
**Post date:** [January 10, 2012, 2:05pm UTC](https://www.ruby-forum.com/t/nginx-http-code-200-404/215606/3 "2012-01-10T14:05:26Z")

</div>

Hello!

On Tue, Jan 10, 2012 at 11:34:59AM +0100, Maik U. wrote:

> ```
> location / {
> proxy_pass
> 
> ```
> 
> [http://xxx.xxx.xxx.xxx:8080](http://xxx.xxx.xxx.xxx:8080);  
> proxy\_redirect off;
> 
> ```
> proxy_set_header Host $host;
> 
> ```

[…]

> got the apache server startpage with the servers hostname.  
> Which server’s hostname? The one matching “[domain.foobar.org](http://domain.foobar.org)”, or  
> something else?

Two possible causes I would consider are:

1. Cache is poisoned by unrelated requests. This may happen if  
you use the same proxy\_cache in other server{} blocks, or if the  
server{} block in question may be used for other hostnames as  
well (i.e. it’s default one).

2. Something wrong happens on backend and it returns wrong  
response(s) sometimes. This may happen for a second or even  
a single request, but as you have cache configured - the response is  
cached for a relatively long time and hence you see it. E.g. this  
may be caused by some periodic backend’s config regeneration.

Maxim D.

---

<div class="post-metadata">

**Author:** ![maikungeriok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@maikungeriok](https://www.ruby-forum.com/u/maikungeriok)\
**Post date:** [January 10, 2012, 11:34am UTC](https://www.ruby-forum.com/t/nginx-http-code-200-404/215606/4 "2012-01-10T11:34:59Z")

</div>

Hello,

Out Config-File is:

server {  
listen xxx.xxx.xxx.xxx:80;  
server\_name [domain.foobar.org](http://domain.foobar.org);  
access\_log  
/var/www/html/domain.foobar.org/logs/nginx\_domain.foobar.org\_access.log  
main;

```
    location / {
            proxy_pass 

```

[http://xxx.xxx.xxx.xxx:8080](http://xxx.xxx.xxx.xxx:8080);  
proxy\_redirect off;

```
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP 

```

$remote\_addr;  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Referer  
$http\_referer;  
proxy\_set\_header Accept-Language  
$http\_accept\_language;

```
            client_max_body_size 64m;
            client_body_buffer_size 128k;

            proxy_connect_timeout 90;
            proxy_send_timeout 90;
            proxy_read_timeout 90;

            proxy_buffer_size 4k;
            proxy_buffers 4 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;

            proxy_cache STATIC;
            proxy_cache_valid 200 30m;
            proxy_cache_valid any 1m;
            proxy_cache_use_stale error timeout 

```

invalid\_header updating http\_500 http\_502 http\_503 http\_504;  
}  
}

As you can see, we have already set the parameter proxy\_set\_header. The  
problem occurs randomly, not all the time. When the problem occurs, we  
got the apache server startpage with the servers hostname.

Maxim D. wrote in post #1040185:

> Hello!
> 
> On Tue, Jan 10, 2012 at 09:42:45AM +0100, Maik U. wrote:
> 
> > Hy,
> > 
> > We have that problem, that a site is not reachable throught nginx with  
> > the domain name (for example [www.foobar.org](http://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](http://www.foobar.org)”. Your backend server won’t recognize it  
> if it’s configured to serve many virtual hosts, and  
> “[www.foobar.org](http://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 D.
