没有合适的资源?快使用搜索试试~ 我知道了~
Nginx之proxy_redirect使用详解
11 下载量 59 浏览量
2020-09-30
00:56:12
上传
评论
收藏 51KB PDF 举报
温馨提示
试读
2页
主要介绍了Nginx之proxy_redirect使用详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
资源推荐
资源详情
资源评论
Nginx之之proxy_redirect使用详解使用详解
主要介绍了Nginx之proxy_redirect使用详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟
随小编过来看看吧
今天在做nginx反向代理apache的时候出了一点点问题,原来后端apache用的端口是8080通过反向代理后,使用wireshark抓
包发现location头域数值为http://192.168.1.154:8080/wuman/ 如果把这个返回给客户端肯定是不可以的,看起来别扭而且还
暴露了apache的具体信息
所以在这里用到了nginx的proxy_redirect指定修改被代理服务器返回的响应头中的location头域跟refresh头域数值
以下是截取nginx的一小段配置文档
server {
listen 80;
server_name www.boke.com;
location / {
proxy_pass http://192.168.1.154:8080;
proxy_redirect off;
}
}
此时我们通过curl查看结果得出
[root@localhost nginx]# curl -I http://www.boke.com/wuman
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.1.154:8080/wuman/
这里location为带有后端服务器实际地址跟端口的响应头信息这样在实际线上是不允许的所以这里我们打算通过proxy_redirect
将被代理服务器的响应头中的location字段进行修改后返回给客户端
server {
listen 80;
server_name www.boke.com;
location / {
proxy_pass http://192.168.1.154:8080;
proxy_redirect http://192.168.1.154:8080/wuman/ http://www.boke.com/wuman/;
}
server {
listen 80;
server_name www.boke.com;
location / {
proxy_pass http://192.168.1.154:8080;
proxy_redirect ~^http://192.168.1.154:8080(.*) http://www.boke.com$1;
}
则curl查看返回结果
[root@localhost nginx]# curl -I http://www.boke.com/wuman
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/wuman/
此时查看location已经变成了我们想要的结果了。 此时通过replacement 301重定向到了我们新的页面
出处:
proxy_redirect
语法:proxy_redirect [ default|off|redirect replacement ]
默认值:proxy_redirect default
使用字段:http, server, location
资源评论
weixin_38632046
- 粉丝: 10
- 资源: 933
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功