iptables 端口转发 + nginx 重定向问题

iptables 端口转发 + nginx 重定向问题

这是我的网络

浏览器 => 代理(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 debian 测试版

在 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 301 重定向到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>

答案1

尝试在你的 nginx 配置文件中添加这个:

port_in_redirect off

我知道这听起来有悖常理,但根据文档,应该是这样的 http://wiki.nginx.org/NginxHttpCoreModule#port_in_redirect

语法:port_in_redirect [ on|off ]

默认值:port_in_redirect on

上下文: http, server, location

指令允许或阻止 nginx 处理的重定向中的端口指示。

如果 port_in_redirect 处于打开状态,则 Nginx 将不是在请求重定向时在url中添加端口。

相关内容