3
回答
Nginx怎么处理非对应端口的端口映射?
开发十年,就只剩下这套Java开发体系了   

标题可能描述不清。详细描述一下我的场景。

由于ISP Ban掉了80端口,所以外网做端口映射的时候将81端口映射为内网ip的80端口。

Nginx的部分配置如下:

server {
  listen 80 default_server;
  etag off;
  port_in_redirect off;
  root /var/www/html;
  server_name _;
  location ^~ /app/ {
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:5601/;
        }
}



现在内网访问没问题,外网81端口访问会遇到nginx的301跳转,跳转的时候带过来的Location不是81,而是80
curl -v http://ip:81/app
* Hostname was NOT found in DNS cache
*   Trying ip...
* Connected to domain (ip) port 81 (#0)
> GET /app HTTP/1.1
> User-Agent: curl/7.35.0
> Host: domain:81
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
* Server nginx is not blacklisted
< Server: nginx
< Date: Sat, 31 Oct 2015 04:12:22 GMT
< Content-Type: text/html
< Content-Length: 178
< Location: http://domain/app/
< Connection: keep-alive
< 
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

可以看到返回的Location并没有带上HOST头中的81端口。google了一下,老外们说是加上port_in_redirect off;就可以了,但是我的配置已经加上了,并没有起作用啊。请教一下这种情况应该怎么配置?

举报
Feng_Yu
发帖于3年前 3回/1K+阅
顶部