没有合适的资源?快使用搜索试试~ 我知道了~
详解proxy_pass根据path路径转发时的"/"问题记录
1 下载量 93 浏览量
2020-09-30
02:18:18
上传
评论
收藏 96KB PDF 举报
温馨提示
主要介绍了详解proxy_pass根据path路径转发时的"/"问题记录,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
资源推荐
资源详情
资源评论






























详解详解proxy_pass根据根据path路径转发时的路径转发时的"/"问题记录问题记录
主要介绍了详解proxy_pass根据path路径转发时的"/"问题记录,小编觉得挺不错的,现在分享给大家,也给大
家做个参考。一起跟随小编过来看看吧
在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/。当加上了/,相当于是绝对根路
径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。
比如下面设置:
location ^~ /wangshibo/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
proxy_pass http://js.test.com/;
}
如上面的配置,如果请求的url是http://servername/wangshibo/test.html会被代理成http://js.test.com/test.html
而如果这么配置
location ^~ /wangshibo/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
proxy_pass http://js.test.com;
}
则请求的url是http://servername/wangshibo/test.html会被代理到http://js.test.com/wangshibo/test.html
当然,可以用如下的rewrite来实现/的功能
location ^~ /wangshibo/
{
proxy_cache js_cache;
proxy_set_header Host js.test.com;
rewrite /wangshibo/(.+)$ /$1 break;
proxy_pass http://js.test.com;
}
列举下面一例
1)第一种配置
[root@BJLX_16_202_V vhosts]# cat ssl-wangshibo.conf
upstream at {
server 192.168.1.202:8080 max_fails=3 fail_timeout=30s;
}
server {
listen 443;
server_name www.wangshibo.com;
ssl on;
### SSL log files ###
access_log logs/wangshibo_access.log;
error_log logs/wangshibo_error.log;
### SSL cert files ###
ssl_certificate ssl/wang.cer;
ssl_certificate_key ssl/wang.key;
location /attendance/ {
proxy_pass http://at; //不需要加上"/"
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}
访问https://www.wangshibo.com/attendance/和http://192.168.1.202:8080/attendance结果是一致的。
2)第二种配置
资源评论


weixin_38720173
- 粉丝: 8
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
