这里我们分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/
}

我们分开来讲:

第一种:

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

第二种:

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

第三种:
location后有/      转发网站没有/
#192.168.1.123-->server name
# :80 ------------> port
#/statc/ ---------->location
#a.html --------->proxy_pass location /static/{
proxy_pass 192.168.2.321:81
}
最后网址经过nginx转向到的网址是 192.168.2.321:81/static/a.html
第四种:
location后有/      转发网站有/
#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/
}
最后网址经过nginx转向到的网址是 192.168.2.321:81/a.html
总结:
从这四种我们可以的看出,当nginx里面匹配时可以把端口后的参数分为path1+path2(其中我在上方标注的location属于path1,proxy_pass属于path2)
proxy_pass  
里面是ip:port+/时nginx最后匹配的网址是 proxy_pass的内容加上path2
里面是ip:port时nginx最后匹配的网址是 proxy_pass的内容加上path1+path2
												

NGINX配置之二: nginx location proxy_pass 后面的url 加与不加/的区别.的更多相关文章

  1. nginx location proxy_pass 后面的url 加与不加/的区别

    在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走. 首先是l ...

  2. nginx proxy_pass后的url加不加/的区别

    在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走. 下面四种 ...

  3. nginx配置后端映射(反向代理proxy_pass)

    说明:配置反向代理proxy_pass和location无关,location后面加不加 / 都可以 1.配置 proxy_pass 时,当在后面的 url 加上了 /,相当于是绝对路径,则 Ngin ...

  4. nginx 配置重定向及nginx配置if

    需求:地址 http://testa/inlinePreview/live.html?id=463738305721405440重定向到 http://testb/shares/live.html?n ...

  5. Nginx阅读笔记(二)之location的用法

    两个配置文件 一: server { listen 80; # # 在本机所有ip上监听80,也可以写为192.168.1.202:80,这样的话,就只监听192.168.1.202上的80口 ser ...

  6. nginx配置:支持phpfastcgi,nginx和php-cgi通信,部分nginx常量解释

    支持phpfastcgi的配置如下: server { listen       8000; server_name  localhost; root F:/home/projects/test; i ...

  7. nginx配置:支持phpfastcgi,nginx和php-cgi通信,部分nginx常量解释

    支持phpfastcgi的配置如下: server { listen 8000; server_name localhost; root F:/home/projects/test; index in ...

  8. Nginx反向代理新篇-使用location对多个URL做反向代理

    1.原理 Nginx解析location/后面的字符串,配置不同的字符串匹配不同的URL进行反向代理. 2.nginx.conf配置文件 worker_processes 1; events { wo ...

  9. Nginx配置Awstats分析Nginx日志笔记

    1.修改Nginx日志格式: log_format json '$remote_addr - $remote_user [$time_local] "$request" '     ...

随机推荐

  1. ping, telnet, tcping 命令使用及对比

    1. ping 命令 ping 命令只能检查 IP 的连通性或网络连接速度,无法具体到某个端口. ping 命令使用 ICMP 协议,跟 IP 协议属于同一层次(网络层).ping 命令在每次发数据包 ...

  2. Learn Python the hard way, ex35 分支和函数

    #!/usr/bin/python #coding:utf-8 from sys import exit def gold_room(): print "this room is full ...

  3. Java Web项目启动执行顺序

    一. 1.启动一个WEB项目,WEB容器会先去读取它的配置文件web.xml,读取<context-param>和<listener>两个节点. 2.接着,容器创建一个Serv ...

  4. 题解1235. 洪水 (Standard IO)

    Description 一天, 一个画家在森林里写生,突然爆发了山洪,他需要尽快返回住所中,那里是安全的.森林的地图由R行C列组成,空白区域用点“.”表示,洪水的区域用“*”表示,而岩石用“X”表示, ...

  5. JS验证数字

    //1.验证数字 var reg = new RegExp("^[0-9]*$"); //var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+ ...

  6. python selenium无法清除文本框内容问题

    正常是我们在清除文本框内容的时候,都会使用 clear() 函数进行清除,但是有时候会出现,清除完成后再点击查询时,文本框的内容会再次自动填充,这个时候我们可以选择以下方式: #清空查询条件drive ...

  7. git统计提交次数

    git log --since="Oct 27 9:16:10 2017 +0800"  --pretty=oneline | wc -l

  8. Linux系统的镜像文件iso下载地址

    CentOS-6.1-x86_64-bin-DVD1.iso 官方网址:http://archive.kernel.org/centos-vault/6.1/isos/x86_64/ 下载链接地址:h ...

  9. 批量调整word 图片大小

    打开文档后,按Alt+F11,在左边Porject下找到ThisDocument,右键插入模块,贴上下面的 Sub Macro()For Each iShape In ActiveDocument.I ...

  10. leetcode.字符串.344反转字符串-Java

    1. 具体题目 编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出.不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一 ...