Здравствуйте, подскажите пожалуйста, может кто-то сталкивался с такой проблемой.
Если сделать запрос:
* 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
Причем вместо 127.0.0.1 в Location подставляется любой ip адрес с которого делается запрос
Если закоментировать опцию
proxy_set_header X-Real-IP $remote_addr;
то возврат становится корректным
* 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
Если обратся напрямую к бекенду то возврат также корректный
* 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
Почему опция X-Real-IP влияет на location?
Конфигурация nginx
server {
listen 80;
server_name example.ru;
access_log /data/www/logs/example.ru-nginx.access.log main;
location / {
include proxy.conf;
}
}
содержимое 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;