编程技术分享平台

网站首页 > 技术教程 正文

详解Nginx proxy_pass 使用(nginx proxy_pass uri)

xnh888 2024-09-22 16:58:17 技术教程 23 ℃ 0 评论

前言

日常不管是研发还是运维,都多少会使用Nginx服务,很多情况Nginx用于反向代理,那就离不开使用proxy_pass,有些同学会对 proxy_pass 转发代理时 后面url加 /、后面url没有 /、后面url添加其它路由等场景,不能很明白其中的意思,下面来聊聊这些分别代表什么意思。

详解

客户端请求 URL https://172.16.1.1/hello/world.html

第一种场景 后面url加 /

location /hello/ {
    proxy_pass http://127.0.0.1/;
}

结果:代理到URL:http://127.0.0.1/world.html

第二种场景 后面url没有 /

location /hello/ {
    proxy_pass http://127.0.0.1;
}

结果:代理到URL:http://127.0.0.1/hello/world.html

第三种场景 后面url添加其它路由,并且最后添加 /

location /hello/ {
    proxy_pass http://127.0.0.1/test/;
}

结果:代理到URL:http://127.0.0.1/test/world.html

第四种场景 后面url添加其它路由,但最后没有添加 /

location /hello/ {
    proxy_pass http://127.0.0.1/test;
}

结果:代理到URL:http://127.0.0.1/testworld.html

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表