Nginx学习——proxy_pass
2024-09-04 19:21:50
参考官网:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
定义:用来设置被代理服务器的协议(http或https)和地址(域名或者IP地址加端口),还可以设置可选的URI
例:proxy_pass http://localhost:8000/uri/
URI按如下规则传送给后端被代理服务器:
客户端请求以http://127.0.0.2:8080/test/xx/yy....为例被监听转发
1、如果proxy_pass使用了URI(就是有/),请求路径与loction路径的匹配部分将被 替换 为proxy_pass中定义的URI
location /test/{
proxy_pass http://127.0.0.3/service/test1/;
}
转发以后的请求为http://127.0.0.3/service/test1/xx/yy...
2、如果proxy_pass没有使用URI,发给被代理服务器的请求路径和客户端发起的请求路径相同,不会被修改
location /test/ {
proxy_pass http://127.0.0.3/service/test1;
}
转发以后的请求为http://127.0.0.3/service/test1/test/xx/yy...
特殊情况:
1、location 使用了正则表达式,这种情况下指令不应该带有URI。
2、使用rewrite指令改变了URI,并使用相同配置处理请求(break):
location /name/ {
rewrite /name/([^/]+) /users?name=$1 break;
proxy_pass http://127.0.0.1;
}
这种情况下,指令定义的URI将被忽略,改变后的URI将被发送给后端服务器。
最新文章
- mysql外键添加error1215
- java:同步和死锁
- 理解android.intent.action.MAIN 与 android.intent.category.LAUNCHER
- android 知识点收集
- github和bitbucket
- 【转】Web应用的组件化开发(二)
- LeetCode57 Insert Interval
- svn: E230001: Server SSL certificate verification failed
- Codeforces Round #115 B. Plane of Tanks: Pro 水题
- Android使用listView,BaseAdapter实现列表页
- ASP.NET Calendar 控件
- [置顶] Guava学习之Multimap
- 【Java】【Flume】Flume-NG源代码分析的启动过程(两)
- bzoj1877
- 2018-2019 20165220 网络对抗 Exp5 MSF基础
- 2018.02.12 noip模拟赛T2
- 写给spring版本的那些事儿
- Introduction to 3D Game Programming with DirectX 11 翻译--开篇
- Linux tomcat自动启动
- vs2013+python+ cocos2d-x-3.3rc0环境搭建