这里我们分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. hdu6228Tree

    Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...

  2. HTMLTestRunner下载生成报告

    HTMLTestRunner下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html,选择HTMLTestRunner.py下载 2.打开显示这 ...

  3. nmon内存分析

    可参考: MemTotal:显示当前服务器物理内存大小,本服务器有8063180 KB≍7874 MB左右. MemFree:显示当前服务器的空闲内存大小,本服务器有5052336 KB≍4934 M ...

  4. 《JAVA设计模式》之工厂方法模式 (Factory)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述工厂方法模式的: 工厂方法模式是类的创建模式,又叫做虚拟构造子(Virtual Constructor)模式或者多态性工厂(Polymor ...

  5. PHP日期加减函数

    <?phpecho "今天:",date('Y-m-d H:i:s'),"<br>";echo "明天:",date('Y ...

  6. [洛谷P1552] [APIO2012]派遣(左偏树)

    这道题是我做的左偏树的入门题,奈何还是看了zsy大佬的题解才能过,唉,我太弱了. 左偏树总结 Part 1 理解题目 很显然,通过管理关系的不断连边,最后连出来的肯定是一棵树,那么不难得出,当一个忍者 ...

  7. python学习第七天流程控制循环while和循环for区别

    流程控制循环是任何编程语言都有一种循环结构,在python while 和break continue 搭配使用,还一种while ....else ......,for循环有序列表和字符串 whil ...

  8. 故事版(storyBoard)-lllegal configuration connection cannot have a prototype objct as

    今天下午做项目的时候.居然出了一个太不是问题的问题了,这个错误太低级了. lllegal configuration connection 'flagImg' cannot have a protot ...

  9. zabbix3.0自动发现磁盘并监控磁盘IO

    Zabbix 版本:3.0 操作系统:Ubuntu16.04 操作环境,在被监控的主机上安装zabbix agent.安装方式为源码包安装. 简要安装步骤: 参考:https://www.zabbix ...

  10. go语言从例子开始之Example33.工作池

    在这个例子中,我们将看到如何使用 Go 协程和通道实现一个工作池 . Example: package main import "fmt" import "time&qu ...