首页 > 系统相关 >NGINX配置之二: nginx location proxy_pass 后面的url 加与不加/的区别.

NGINX配置之二: nginx location proxy_pass 后面的url 加与不加/的区别.

时间:2023-01-12 10:33:26浏览次数:297  
标签:NGINX url 192.168 nginx proxy pass 81 2.321 location

先给出结果
(1)^~开头是前缀匹配,location后面加 / 也是前缀匹配,只不过匹配范围比不加 / 要小
(2)proxy_pass 端口后面没有 / ,则会将 location 及其后缀的内容完全拼接到 proxy_pass 所配置的地址后
(3)proxy_pass 端口后面有 /,则仅会将 location 的后缀拼接到 proxy_pass 所配置的地址后

 

这里我们分4种情况讨论

这里我们请求的网站为:192.168.1.123:80/static/a.html

server{
port  80,
server name  192.168.1.123

location /static{
proxy_pass  192.168.2.321:81
}

location /static{
proxy_pass  192.168.2.321:81/
}

location /static/{
proxy_pass  192.168.2.321:81
}

location /static/{
proxy_pass  192.168.2.321:81/
}
整个配置文件
#192.168.1.123->server name
# :80 ---------> port
#/statc ------->location
#/a.html ------>proxy_pass 

location /static{
proxy_pass  192.168.2.321:81
}
第一种: location后没有/ 转发网站没有/
最后网址经过nginx转向到的网址是 192.168.2.321:81/static/a.html
结果1
#192.168.1.123---->server name
# :80 ------------> port
#/statc ---------->location
#/a.html --------->proxy_pass 

location /static{
proxy_pass  192.168.2.321:81/
}
第二种: location后没有/ 转发网站有/
最后网址经过nginx转向到的网址是 192.168.2.321:81/a.html
结果2
#192.168.1.123-->server name
# :80 ------------> port
#/statc/ ---------->location
#a.html --------->proxy_pass 

location /static/{
proxy_pass  192.168.2.321:81
}
第三种: location后有/ 转发网站没有/
最后网址经过nginx转向到的网址是 192.168.2.321:81/static/a.html
结果3
#192.168.1.123-->server name
# :80 ------------> port
#/statc/ ---------->location(path1)
#a.html --------->proxy_pass (path2)

location /static/{
proxy_pass  192.168.2.321:81/
}
第四种: location后有/ 转发网站有/
最后网址经过nginx转向到的网址是 192.168.2.321:81/a.html
结果4

总结:
从这四种我们可以的看出,当nginx里面匹配时可以把端口后的参数分为path1+path2(其中我在上方标注的location属于path1,proxy_pass属于path2)
当proxy_pass
端口后面有/时,nginx最后匹配的网址是 proxy_pass的内容加上path2(location的后缀)
端口后面没有/时,nginx最后匹配的网址是 proxy_pass的内容加上path1+path2(location及其后缀的内容)

 


参考链接:https://blog.csdn.net/s_156/article/details/124059367

标签:NGINX,url,192.168,nginx,proxy,pass,81,2.321,location
From: https://www.cnblogs.com/zt007/p/17045758.html

相关文章

  • 【javascript】关于 canvas.toDataURL()
    在工作中遇到了奇怪的问题,在此记录。 一、定义canvas.toDataURL()方法是返回一个包含图片展示的数据URL。可以使用 type 参数其类型,默认为PNG格式,图片的分辨率为9......
  • nginx配置
    map$http_upgrade$connection_upgrade{defaultupgrade;''close;}server{listen8888;server_namelocalhost;location/{proxy_passhttp:/......
  • 3.4 urlopen()方法的源代码
    ---   --------------------------------------------------------------------------------------------------------------------------------------------------......
  • 3.2 urllib.request发送get与post请求
      --正常网页读取importurllib.requesturl='https://www.lingdianshuwu.com/'#发送请求resp=urllib.request.urlopen(url)#这个网页只有gethtml=resp.rea......
  • nginx for windows
    nginx.confworker_processes8;error_loglogs/info;events{worker_connections2048;}http{includemime.types;default_typeapplica......
  • nginx反向代理
     nginx反向代理location/edu{proxy_passhttps://c3wedu.hapu.net;proxy_set_headerHostc3wedu.hapu.net;proxy_set_headerX-Real-IP$re......
  • Nginx 进阶篇
    目录Nginx进阶篇五、服务配置1、配置成系统服务2、配置环境变量六、部署静态资源1、概述2、配置指令2.1listen2.2server_name2.3location2.4root2.5alias2.6i......
  • thinkphp安装在子目录的nginx配置
    进行URL重写,将默认访问URL中的index.php?s=通过rewrite隐藏location/blog/{indexindex.phpindex.htmlindex.htm;if(!-e$request_filename){rewrite......
  • nginx反向代理,解决vue项目跨域问题
     nginx的配置:  把/api转到另一个域名下#PROXY-START/apilocation/api{expires12h;if($request_uri~*"(php|jsp|cgi|asp|aspx)"){expires0......
  • VUE项目的API项目的nginx配置
    #PROXY-START/apilocation/api{expires12h;if($request_uri~*"(php|jsp|cgi|asp|aspx)"){expi......