Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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>
share|improve this question

migrated from stackoverflow.com Jun 7 '10 at 8:02

This question came from our site for professional and enthusiast programmers.

1 Answer 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.