HEAD and Nginx nginx-0.6.36-1.el5

Hi,

We are trying to setup Nginx as a reverse proxy in front of Apache.
A HEAD gives a 404 with Nginx, when connecting directly to port 81
(Apache) we get an 301 and then a 200 error.
Is my nginx version (0.6.36 allowing HEAD requests?)

kind regards,

Michiel

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,6366#msg-6366

On Thu, Sep 10, 2009 at 03:13:59PM -0400, xmichielx wrote:

Hi,

We are trying to setup Nginx as a reverse proxy in front of Apache.
A HEAD gives a 404 with Nginx, when connecting directly to port 81 (Apache) we get an 301 and then a 200 error.
Is my nginx version (0.6.36 allowing HEAD requests?)

Yes, nginx supports HEAD from the very start.

Hi Igor,

Thanks, do you know why the HEAD is returning a 301 with Apache and a
404 with Nginx?

The nginx access.log:
172.23.3.14 - - [10/Sep/2009:20:45:12 +0200] HEAD /web/MYCE.htm HTTP/1.1
“404” 0
“-” “Mozilla/4.06 (WinNT; I)” “172.21.0.5, 172.21.0.5”
172.21.0.5 - - [10/Sep/2009:20:45:12 +0200] HEAD /MYCE.htm HTTP/1.0
“404” 0 “-”
“Mozilla/4.06 (WinNT; I)” “-”

The apache log:

172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYLER.htm HTTP/1.0”
404 - “-” “Mozilla/4.06 (WinNT; I)”
172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYCE.htm HTTP/1.0”
404 - “-” “Mozilla/4.06 (WinNT; I)”
stmycew01.hf.info.nl - - [10/Sep/2009:20:12:58 +0200] “GET /404.html
HTTP/1.0” 200 6507 “-” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1)l”
stmycew01.hf.info.nl - - [10/Sep/2009:20:12:58 +0200] “GET /404.html
HTTP/1.0” 200 6507 “-” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1)l”
stmycew01.hf.info.nl - - [10/Sep/2009:20:12:58 +0200] “HEAD
/web/MYLER.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”

We also see some Apache DNS lookup proxy messages:
proxy: DNS lookup failure for: 172.23.3.14, 172.23.3.14 returned by
/MYLER.htm
proxy: DNS lookup failure for: 172.23.3.14, 172.23.3.14 returned by
/MYCE.htm
proxy: DNS lookup failure for: 172.23.3.14, 172.23.3.14 returned by
/MYLER.htm

Only apache on port 80 (normal setup):

stmycew01.hf.info.nl - - [11/Sep/2009:10:42:57 +0200] “HEAD /MYLER.htm
HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”
stmycew01.hf.info.nl - - [11/Sep/2009:10:42:57 +0200] “HEAD
/web/MYLER.htm HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”

If you want I can post the nginx.conf and the virtual host?

Kind regards and thanks for your kind help :slight_smile:

Michiel

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,6435#msg-6435

On Fri, Sep 11, 2009 at 04:48:46AM -0400, xmichielx wrote:

The apache log:
proxy: DNS lookup failure for: 172.23.3.14, 172.23.3.14 returned by /MYCE.htm

Kind regards and thanks for your kind help :slight_smile:

Did you see in nginx error_log ?

Hello!

On Fri, Sep 11, 2009 at 04:48:46AM -0400, xmichielx wrote:

The apache log:

172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYLER.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”
172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYCE.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”

So it’s Apache returned 404, right?

Looks like the problem is incorrect virtual host in Apache was
picked up. Probably you just need correct Host header to be
passed into Apache. By default nginx uses upstream name, you
probably need

proxy_set_header  Host  $host;

in nginx.conf.

Maxim D.

Hello Maxim,

This is my nginx.conf server part:

server {
    listen       80;
    server_name  _;

location / {
proxy_pass http://172.23.3.14:81;
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_max_temp_file_size 0;

    client_max_body_size       2g;
    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;

    }

  }

Can you what I am doing wrong here?

Kind regards,

Michiel

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,6488#msg-6488

Hello!

On Fri, Sep 11, 2009 at 10:21:44AM -0400, xmichielx wrote:

        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;

[…]

Can you what I am doing wrong here?

I see no obvious problems. Try looking into Apache config (and
try tcpdump to see what’s happening on the wire between nginx and
Apache).

Maxim D.

On Friday, September 11, 2009 at 17:21:44, xmichielx wrote:

x> server {
x> listen 80;
x> server_name _;

x> location / {
x> proxy_pass http://172.23.3.14:81;
x> proxy_redirect off;

x> Can you what I am doing wrong here?

you disable proxy_redirect and set backend on different port.

http://wiki.nginx.org/NginxHttpProxyModule#proxy_redirect

backend may discover nonstandart port and it may generate 301 redirect
including
port number. but if proxy_redirect is off - nginx can not rewrite such
redirect.

better approach - configure backend on same port as frontend,
(80 in this case) but on different ip, for example 127.0.0.1,
or, at least, do not disable proxy_redirect.

fragments of my working apache backend config:

========================================================

Listen 127.0.0.1:80

NameVirtualHost *

<VirtualHost *>
ServerName unknown-apache.example.com
# … ^^^ default apache virtual host

<VirtualHost *>
ServerName virtualhost1.example.com
# …

<VirtualHost *>
ServerName virtualhost2.example.com
# …

========================================================

fragments of my corresponding nginx frontend config:

========================================================

http {

proxy_set_header  Host $host;
proxy_set_header  X-Real-IP $remote_addr;
proxy_set_header  X-Nginx-Scheme $scheme;

server {
    listen 80 default;
    server_name unknown-nginx.example.com;
    # ... ^^^ default nginx virtual host
}

server {
    listen 80;
    server_name virtualhost1.example.com;
    # ...
    location / {
        proxy_pass http://127.0.0.1/;
    }
}

server {
    listen 80;
    server_name virtualhost2.example.com;
    # ...
    location / {
        proxy_pass http://127.0.0.1/;
    }
}

}

========================================================

also

proxy_pass http://127.0.0.1/;

and

proxy_pass http://127.0.0.1;

are two somewhat different directives for details see
http://wiki.nginx.org/NginxHttpProxyModule#proxy_pass

Hi,

Is the only option to change the port?
Do I have to run nginx and apache on the same ports but diffirent
ip-adresses? It would be nicer to let Apache run on a diffirent port and
nginx on port 80.
I also understand that I have to rewrite mu URI with a trailing / and
use the proxy_redirect on; ?

Thanks for the help.

Regards,

Michiel

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,6811#msg-6811

Hi,

I tried to configure proxy_redirect but still got the 404.
This is my nginx.conf:

server {
listen 80;
server_name _;

location / {
proxy_pass http://172.23.3.14:81/;
# proxy_redirect on;
proxy_redirect / /;

        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_max_temp_file_size 0;

    client_max_body_size       2g;
    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;

    }

  }

This my httpd.conf:

ServerAdmin [email protected]
ServerName 172.23.3.14
CustomLog logs/css-proxy-access.log combined
DocumentRoot /var/www/www.staging.myler.nl/web-docs
ProxyPass / http://www.staging.myler.nl/

But still not working :frowning:
I have disabled on other nginx + apache hosts the proxy_redirect and is
working but do I understand that I have to enable it for HEAD requests?
And what am I missing that it still isn’t working when I enable the
proxy_redirect?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,6905#msg-6905

On Monday, September 14, 2009 at 11:37:50, xmichielx wrote:

x> Is the only option to change the port?

no.

x> Do I have to run nginx and apache on the same ports but diffirent
ip-adresses?

this is just simpler variant, - from my point of view.

x> It would be nicer to let Apache run on a diffirent port and nginx on
port 80.

in this case you also need to configure proxy_redirect.

On Monday, September 14, 2009 at 17:21:42, xmichielx wrote:

x> I tried to configure proxy_redirect but still got the 404.

see into error.log and access.log from nginx and apache for cause.
if not help with default loglevel - set loglevel to info or debug.

x> This my httpd.conf:

x> ServerAdmin [email protected]
x> ServerName 172.23.3.14
x> CustomLog logs/css-proxy-access.log combined
x> DocumentRoot /var/www/www.staging.myler.nl/web-docs
x> ProxyPass / http://www.staging.myler.nl/

x> But still not working :frowning:

x> I have disabled on other nginx + apache hosts the proxy_redirect
x> and is working but do I understand that I have to enable it for HEAD
requests?

HEAD requests in nginx enabled by default.

x> And what am I missing that it still isn’t working when I enable the
proxy_redirect?

what you missing - you can know from logfiles of
http://www.staging.myler.nl/

PS looks like this is problem with your backend, this is not nginx
issue:

lwp-request -m HEAD -U -s -S -e http://staging.myler.nl/


HEAD http://www.myler.nl/web/persoon/staging
User-Agent: lwp-request/2.08

HEAD http://staging.myler.nl/ --> 302 Found
HEAD http://www.myler.nl/web/persoon/staging --> 404 Not Found
Connection: close
Date: Mon, 14 Sep 2009 16:06:22 GMT
Content-Type: text/html; charset=UTF-8
Client-Date: Mon, 14 Sep 2009 16:06:22 GMT
Client-Peer: 80.79.193.91:80
Client-Response-Num: 1

lwp-request -m HEAD -U -s -S -e http://www.staging.myler.nl/


HEAD http://www.staging.myler.nl/
User-Agent: lwp-request/2.08

HEAD http://www.staging.myler.nl/ --> 403 Forbidden
Connection: close
Date: Mon, 14 Sep 2009 16:06:54 GMT
Server: Apache
Content-Type: text/html; charset=iso-8859-1
Client-Date: Mon, 14 Sep 2009 16:06:54 GMT
Client-Peer: 80.79.193.92:80
Client-Response-Num: 1

On Tuesday, September 15, 2009 at 11:32:15, xmichielx wrote:

The apache log:

172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYLER.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”
172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYCE.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”
stmycew01.hf.info.nl - - [10/Sep/2009:20:12:58 +0200] “GET /404.html HTTP/1.0” 200 6507 “-” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)l”
stmycew01.hf.info.nl - - [10/Sep/2009:20:12:58 +0200] “GET /404.html HTTP/1.0” 200 6507 “-” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)l”
stmycew01.hf.info.nl - - [10/Sep/2009:20:12:58 +0200] “HEAD /web/MYLER.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”

your apache return 404 error to nginx, and nginx return 404 error to
client.
there is no problems with nginx - it work as expected.

Only apache on port 80 (normal setup):

stmycew01.hf.info.nl - - [11/Sep/2009:10:42:57 +0200] “HEAD /MYLER.htm HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”
stmycew01.hf.info.nl - - [11/Sep/2009:10:42:57 +0200] “HEAD /web/MYLER.htm HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”

x> The strange thing is: HEAD works with a redirect in a normal Apache
setup
x> but with a Nginx redirect setup (see my config above here) I get a
404
x> from the Apache and Nginx, I think the request isn’t correctly
entering Apache.

useless. make tcpdump of tcp session between nginx frontend
and apache backend and see - correct request or not correct.

btw, apache save the request to logfile: “HEAD /MYLER.htm HTTP/1.0”
there is nothing incorrect in this request, from my point of view.

x> Can it be a change in the HTTP 1.0 and HTTP1.1 diffirence?

make HTTP/1.1 and HTTP/1.0 request
to backend from curl and get to know.

also make direct request to 80 port and 81 port of apache,
don’t using nginx at all and also see - it work as expected or not.

for all four requests ( HTTP/1.1 or HTTP/1.0 ) x ( port 80 or port 81 )
use only curl, not web browser. after such debug situation must be
clear.

Hi Gena,

That staging is not working from your side is because of an ACL in
Apache.
I can not enable the debug option because I use the RPM and it is not
enabled by default:
Starting nginx: 2009/09/15 10:26:21 17939#0: unknown log format “debug”
in /etc/nginx/nginx.conf:55

The logfiles are the same like the one I send:

172.21.0.5 - - [10/Sep/2009:20:12:56 +0200] “HEAD /MYCE.htm HTTP/1.0” 404 - “-” “Mozilla/4.06 (WinNT; I)”

Only apache on port 80 (normal setup):

stmycew01.hf.info.nl - - [11/Sep/2009:10:42:57 +0200] “HEAD /MYLER.htm HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”
stmycew01.hf.info.nl - - [11/Sep/2009:10:42:57 +0200] “HEAD /web/MYLER.htm HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”

The strange thing is: HEAD works with a redirect in a normal Apache
setup but with a Nginx redirect setup (see my config above here) I get a
404 from the Apache and Nginx, I think the request isn’t correctly
entering Apache.
Can it be a change in the HTTP 1.0 and HTTP1.1 diffirence?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,7060#msg-7060

On Monday, September 21, 2009 at 12:10:16, xmichielx wrote:

x> But how can I check with curl the Apache settings
x> and with HTTP 1.0 and HTTP 1.1 diffirence?

=================================

$ man curl | grep -a2 “HTTP 1.0”

   -0/--http1.0
          (HTTP)  Forces curl to issue its requests using HTTP 1.0 

instead
of using its internally preferred: HTTP 1.1.

=================================

use curl with and without -0 parameter, for generating HTTP 1.0 and HTTP
1.1 requests.

how make HEAD request instead GET one you also may read in curl man page
/ documentation.

x> And after that you want me to do the same tests with curl with Nginx
in front of Apache?

I am sure, bug with HEAD requests not in nginx, but in your backend.
first debug apache, and achieve expected work in all four cases:

make direct request to 80 port and 81 port of apache,
don’t using nginx at all and see - it work as expected or not.

for all four requests ( HTTP/1.1 or HTTP/1.0 ) x ( port 80 or port 81 )
use only curl, not web browser. after such debug situation must be
clear.

I already found some diffirences with the HEAD request from Curl or from
our content switch:

css:
stmycew01.hf.info.nl - - [21/Sep/2009:13:46:10 +0200] “HEAD
/web/MYLER.htm HTTP/1.1” 200 - “-” “Mozilla/4.06 (WinNT; I)”

curl head 1.1 test:
10.101.111.112 - - [21/Sep/2009:13:47:08 +0200] “HEAD /web/MYLER.htm
HTTP/1.1” 404 - “-” “curl/7.19.6 (i386-pc-win32) libcurl/7.19.6
zlib/1.2.3”

curl head 1.0 test:
10.101.111.112 - - [21/Sep/2009:13:47:31 +0200] “HEAD /web/MYLER.htm
HTTP/1.0” 404 - “-” “curl/7.19.6 (i386-pc-win32) libcurl/7.19.6
zlib/1.2.3”

c:\tools>curl -I -1 http://stbizzw01:80/web/MYLER.htm
HTTP/1.1 404 Not Found
Date: Mon, 21 Sep 2009 11:47:08 GMT
Content-Type: text/html; charset=UTF-8
Connection: close

c:\tools>curl -I -0 http://stbizzw01:80/web/MYLER.htm
HTTP/1.1 404 Not Found
Date: Mon, 21 Sep 2009 11:47:31 GMT
Content-Type: text/html; charset=UTF-8
Connection: close

I also think it is the backend but I can not see what is different?
I also find out that the css request are looking to coming internally
from the CMS (or are rerouted through the CMS).

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,8100#msg-8100

Hi Gena,

A stupid question from me:

But how can I check with curl the Apache settings and with HTTP 1.0 and
HTTP 1.1 diffirence?
And after that you want me to do the same tests with curl with Nginx in
front of Apache?

Kind regards,

Michiel

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6366,8074#msg-8074

On Monday, September 21, 2009 at 15:02:21, xmichielx wrote:

x> curl -I -0 http://stbizzw01:80/web/MYLER.htm
x> HTTP/1.1 404 Not Found
x> Date: Mon, 21 Sep 2009 11:47:31 GMT
x> Content-Type: text/html; charset=UTF-8
x> Connection: close

even direct requests to backend return 404 error.

this prove what no problems with nginx in your case.

x> I also think it is the backend but I can not see what is different?

sorry, I don’t know.

try enable debug logs at backends, and/or ask CMS developers.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs