nginx 隐藏http信息中location 部分信息
nginx -redirect隐藏http信息中location部分信息
server { listen 80; server_name www.boke.com; location / { proxy_pass http://192.168.3.3:8080; proxy_redirect off; } } http://www.boke.com后,将显示http://192.168.3.3:8080的web信息 代理成功
通过curl命令查看返回的信息
[root@localhost nginx]# curl -I http://www.boke.com/web HTTP/1.1 301 Moved Permanently Server: nginx Date: Thu, 24 Dec 2015 12:02:00 GMT Content-Type: text/html; charset=iso-8859-1 Connection: keep-alive Location: http://192.168.3.3:8080/web/
这里location为带有后端服务器实际地址跟端口的响应头信息这样在实际线上是不允许的所以这里我们打算通过proxy_redirect将被代理服务器的响应头中的location字段进行修改后返回给客户端
进行重新配置 -对重定向的地址起别名:
server { listen 80; server_name www.boke.com; location / { proxy_pass http://192.168.3.3:8080; proxy_redirect http://192.168.3.3:8080/web/ http://www.boke.com/web/; } server { listen 80; server_name www.boke.com; location / { proxy_pass http://192.168.3.3:8080; proxy_redirect ~^http://192.168.3.3:8080(.*) http://www.boke.com$1; }
curl查看返回结果
[root@localhost nginx]# curl -I http://www.boke.com/web HTTP/1.1 301 Moved Permanently Server: nginx Date: Thu, 24 Dec 2015 12:08:34 GMT Content-Type: text/html; charset=iso-8859-1 Connection: keep-alive Location: http://www.boke.com/web/
代理后端的服务器信息将不再显示,取而代之的是只显示访问代理本身
嗨,朋友既然来了何不关注一下!
春有百花秋有月,夏有凉风冬有雪!