nginx proxy_pass 的路径问题
2022/7/2 5:20:06
本文主要是介绍nginx proxy_pass 的路径问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:
location /some/path/ {
proxy_pass http://127.0.0.1;
}
In some cases, the part of a request URI to be replaced cannot be determined:
When location is specified using a regular expression, and also inside named locations.
In these cases, proxy_pass should be specified without a URI.
总结起来就是 proxy_pass 过程中会 使用 proxy_pass 中special 的url 替换命中的url,但是如果location 中存在rewrite 或者 要使用变量 那proxy_pass 中special 的url将不再生效
测试文件
server { server_name songtest.com; #access_log /tmp/songtest.log main; listen 80 ; location / { proxy_pass http://127.0.0.1:8080/zz1; } location /app { proxy_pass http://127.0.0.1:8080; } # songtest.com/app/1 http://127.0.0.1:8080/app/1 location /app2 { proxy_pass http://127.0.0.1:8080/zz2; } # songtest.com/app2/1 http://127.0.0.1:8080/zz2/1 location ^~ /app3 { proxy_pass http://127.0.0.1:8080/zz2; } # songtest.com/app3/1 http://127.0.0.1:8080/zz2/1 location /app5 { rewrite (.*) /users?name=$1 break; proxy_pass http://127.0.0.1/useless; } # songtest.com/app5/1 http://127.0.0.1:8080/users?name=/app5/1 }
openresty 中使用的切忌
以上配置在 openresty 添加lua配置后失效
这篇关于nginx proxy_pass 的路径问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享
- 2024-08-14nginx 让访问带有/relid的地址返回404 ,例子 /relid-x-0.36-y-131.html-icode9专业技术文章分享
- 2024-08-14nginx 判断地址有/statics/的路径,指向到/home/html/statics/目录-icode9专业技术文章分享