Answer the question
In order to leave comments, you need to log in
Strange behavior of nginx when redirecting, or is this the norm?
Hello, please let me know if anyone has come across this problem.
If you make a request:
* About to connect() to example.ru port 80 (#0)
* Trying 127.0.0.1… connected
* Connected to example.ru (127.0.0.1) port 80 (#0)
> GET /v HTTP/ 1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: example.ru
> Accept: */*
>
< HTTP/1.1 301 MOVED PERMANENTLY
< Server: nginx/1.3.3
< Date: Tue, 31 Jul 2012 10:36:56 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 0
< Connection: close
< Location: 127.0.0.1/v/
< Vary: Accept-Encoding
<
* Closing connection #0
Moreover, instead of 127.0.0.1, any ip address from which the request is made is substituted in Location.
If you comment out the option
proxy_set_header X-Real-IP $remote_addr;
then the return becomes valid
* About to connect() to example.ru port 80 (#0)
* Trying 127.0.0.1… connected
* Connected to example.ru (127.0.0.1) port 80 (#0)
> GET /v HTTP/ 1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: example.ru
> Accept: */*
>
< HTTP/1.1 301 MOVED PERMANENTLY
< Server: nginx/1.3.3
< Date: Tue, 31 Jul 2012 10:37:25 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 0
< Connection: close
< Location: example.ru/v/
< Vary: Accept-Encoding
<
* Closing connection #0
If you contact the backend directly, then the return is also correct
* About to connect( ) to example.ru port 8080 (#0)
* Trying 127.0.0.1… connected
* Connected to example.ru (127.0.0.1) port 8080 (#0)
> GET /v HTTP/1.1
> User-Agent: curl/7.19 .7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: example.ru
> Accept: */*
>
< HTTP/ 1.1 301 MOVED PERMANENTLY
< Server: Apache
< Date: Tue, 31 Jul 2012 10:38:21 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 0
< Connection: close
< Location: example.ru :8080/v/
< Vary: Accept-Encoding
<
* Closing connection #0
Why does the X-Real-IP option affect location?
nginx
server configuration {
listen 80;
server_name example.ru;
access_log /data/www/logs/example.ru-nginx.access.log main;
location / {
include proxy.conf;
}
}
contents of proxy.conf
proxy_pass 127.0.0.1 :8080/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header Range "";
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;
client_max_body_size 101m;
client_body_buffer_size 128k;
proxy_connect_timeout 70;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 32k;
proxy_buffers 8 16k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
Answer the question
In order to leave comments, you need to log in
VBart, thanks for the tip, I tried to go directly to the backend with headers, and got the expected error, then I went to the mod_rpaf website and saw that they are in the new version just with X-Real-IP, X-Forwarded-For fixed something , apparently these fixes led to this error. Thank you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question