2

Here is my network

browser => proxy(iptables port forward) => nginx server

proxy: 192.168.10.204, forward 192.168.10.204:22080 to 192.168.10.10:80 nginx server: 192.168.10.10

nginx version:0.7.65 debian testing

in nginx settings, I set:

server_name _;
server_name_in_redirect off;

because my server has no domain

now, access 192.168.10.10/index.html or 192.168.10.10/foobar is ok

then access 192.168.10.204:22080/index.html is ok

but access 192.168.10.204:22080/foobar, nginx 301 redirect to http://192.168.10.204/foobar

how to fix?

thanks

telnet 192.168.10.204 22080
Trying 192.168.10.204...
Connected to 192.168.10.204.
Escape character is '^]'.
GET /index.html HTTP/1.1
Host: 192.168.10.10

HTTP/1.1 200 OK
Server: nginx/0.7.65
Date: Fri, 28 May 2010 10:07:29 GMT
Content-Type: text/html
Content-Length: 12
Last-Modified: Fri, 28 May 2010 07:25:12 GMT
Connection: keep-alive
Accept-Ranges: bytes

hello world



telnet 192.168.10.204 22080
Trying 192.168.10.204...
Connected to 192.168.10.204.
Escape character is '^]'.
GET /test2 HTTP/1.1
Host: 192.168.10.10

HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Date: Fri, 28 May 2010 10:04:20 GMT
Content-Type: text/html
Content-Length: 185
Location: http://192.168.10.10/test2/
Connection: keep-alive

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/0.7.65</center>
</body>
</html>

1 Answer 1

1

try add this in your nginx config file:

port_in_redirect off

I know it sounds counter-intuitive, but it supposed to be that according to the docs http://wiki.nginx.org/NginxHttpCoreModule#port_in_redirect

syntax: port_in_redirect [ on|off ]

default: port_in_redirect on

context: http, server, location

Directive allows or prevents port indication in redirects handled by nginx.

If port_in_redirect is on, then Nginx will not add the port in the url when the request is redirected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy