iptables端口转发+ nginxredirect问题

这是我的networking

浏览器=>代理(iptables端口转发)=> nginx服务器

代理:192.168.10.204,转发192.168.10.204:22080到192.168.10.10:80 nginx服务器:192.168.10.10

nginx版本:0.7.65 debiantesting

在nginx设置中,我设置了:

server_name _; server_name_in_redirect off; 

因为我的服务器没有域名

现在,访问192.168.10.10/index.html或192.168.10.10/foobar是好的

那么访问192.168.10.204:22080/index.html是可以的

但访问192.168.10.204:22080/foobar,nginx 301redirect到http://192.168.10.204/foobar

怎么修?

谢谢

 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> 

尝试在你的nginxconfiguration文件中添加这个:

 port_in_redirect off 

我知道这听起来反直觉,但它应该是根据文档http://wiki.nginx.org/NginxHttpCoreModule#port_in_redirect

语法:port_in_redirect [on | off]

默认:port_in_redirect on

上下文:http,服务器,位置

指令允许或防止由nginx处理的redirect中的端口指示。

如果port_in_redirect处于打开状态,那么在请求被redirect的时候,Nginx将不会在url中添加端口。