本文转载自:https://pureage.info/2013/10/31/130.html

由于工作需要,开始分析nginx的proxy模块,在分析之前,当然要先会用了。于是开始熟悉该模块的一些指令,其中最基本的指令要属proxy_pass了。nginx的英文文档总是看着感觉有些别扭,于是按惯例先google了一些文章。

这一搜,就掉进坑里了。

这些文章里都把proxy_pass的目标地址是形如“127.0.0.1:8090”和“127.0.0.1:8090/”分开讨论,认为后者“/“的作用是删除url中匹配的部分,然后再讨论目标地址中带了uri的情况。

其实根本没这么复杂,只有两种情况:

(1)目标地址中不带uri。即proxy_pass的参数形如”http://127.0.0.1:8090"。 此时新的目标url中,匹配的uri部分不做修改,原来是什么样就是什么样。

(2)目标地址中带uri。即proxy_pass的参数形如“http://127.0.0.1:8090/dir1/dir2"

此时新的目标url中,匹配的uri部分将会被修改为该参数中的uri,如”http://127.0.0.1:8888/dir1/dir2."

有人说,你没有讨论ip和端口后带不带”/“的区别。其实是不需要的,因为”/“本身就是一种uri,很明显属于上面的第二种情况,只不过是把原来的uri修改为了现在的uri(”/”),看上去,像是删除了原url中匹配的部分。如果不理解这一点,就会总想着去牢记、区分结尾带不带”/“的情况。
官方文档也是这么叙述的,根本没有提及半句“/“:

A request URI is passed to the server as follows:

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;
}

测试部分如下。

如果配置为:

server {
listen 9090;
access_log /home/strider/project/nginx/nginx-1.4.2/log/access_9090.log;
location /test1/test2/{
proxy_pass http://127.0.0.1:8090;
}
}

则有如下对应关系:

127.0.0.1:9090/test1/test2/echo1----->127.0.0.1:8090/test1/test2/echo1
127.0.0.1:9090/test1/test2/---->127.0.0.1:8090/test1/test2

如果配置为:

server {
listen 9090;
access_log /home/strider/project/nginx/nginx-1.4.2/log/access_9090.log;
location /test1/test2/{
proxy_pass http://127.0.0.1:8090/;
}
}

则有如下对应关系:

127.0.0.1:9090/test1/test2/echo1----->127.0.0.1:8090/echo1
127.0.0.1:9090/test1/test2/---->127.0.0.1:8090/

如果配置为:
>server {
listen 9090;
access_log /home/strider/project/nginx/nginx-1.4.2/log/access_9090.log;
location /test1/test2/{
proxy_pass http://127.0.0.1:8090/test1;
}
}

则有如下对应关系:

127.0.0.1:9090/test1/test2/echo1----->127.0.0.1:8090/test1echo1
127.0.0.1:9090/test1/test2/---->127.0.0.1:8090/test1

如果配置为:

server {
listen 9090;
access_log /home/strider/project/nginx/nginx-1.4.2/log/access_9090.log;
location /test1/test2/{
proxy_pass http://127.0.0.1:8090/test3/test4/test5;
}
}

则有如下对应关系:

127.0.0.1:9090/test1/test2/echo1----->127.0.0.1:8090/test3/test4/test5echo1
127.0.0.1:9090/test1/test2/---->127.0.0.1:80990/test3/test4/test5

转载于:https://www.cnblogs.com/bigdatadiary/p/10960596.html

关于Nginx参数路径问题的问题相关推荐

  1. Nginx根据路径设置静态资源

    Nginx根据路径设置静态资源 示例nginx.conf user root; worker_processes auto; error_log /var/log/nginx/error.log; p ...

  2. 正则化检测TR069的参数路径是否合法

    以下为一些基本的参数路径 Device.Ethernet.Interface.{5}.Enable Device.Ethernet.Interface.{5}.Status Device.Ethern ...

  3. nginx目录路径重定向

    nginx目录路径重定向 目录 1 nginx修改root映射 2 通过nginx rewrite内部跳转实现访问重定向 3 nginx设置别名alias映射实现 4 通过nginx的permanen ...

  4. linux 查看nginx 启动路径

    由于系统中有多个nginx目录,不知道哪一个哪一个才是真正的正在运行的服务,记录查看nginx启动路径定位. 1.查找nginx的pid [root@wskh xpe]# netstat -anop ...

  5. nginx服务器资源路径配置文件,查看nginx配置文件路径和资源文件路径的方法

    本文关键详细介绍了查询nginx配置文件路径和資源文件路径,文中给大伙儿详细介绍的十分详尽,对大伙儿的学习培训或工作中具备一定的参照效仿使用价值,必须的盆友能够参照下 查询nginx配置文件路径 根据 ...

  6. 查nginx配置文件路径

    查看nginx配置文件路径 进入nginx安装目录(我的是/usr/local/nginx-1.7.8/) 进入sbin目录,输入 ./nginx -t 查看nginx配置文件路径以及该文件语法是否正 ...

  7. 查看nginx配置文件路径和资源文件路径

    查看nginx配置文件路径 通过 nginx -t nginx -t命令的原始作用是用来验证nginx配置文件格式和配置是否存在异常,通过该命令会输出nginx的配置文件的路径和验证结果,在输出结果中 ...

  8. linux系统下查看nginx配置文件路径

    查看nginx配置文件路径 nginx -t或者在nginx安装目录执行sbin/nginx -t 查看nginx安装目录 whereis nginx

  9. nginx参数配置(3)待续

    和客户端请求相关的配置: 12.keepalive_timeout timeout [header_timeout]; 设定保持连接的超时时长,0表示禁止长连接 :默认为75s; 13.keepali ...

最新文章

  1. [Leetcode] Combinations 组合数
  2. java自增自减很难理解_关于java中自增,自减,和拓展运算符的小讨论
  3. 父类一实现serializable_我的java基础学习易错点和易忘点总结(一)
  4. 嵌入式开发中模拟SPI的驱动
  5. 【LeetCode】3月21日打卡-Day6
  6. 为什么互联网公司需要测试人员?
  7. Cache满载的LRU置换
  8. 详解 ManualResetEvent
  9. 传感器的原理及应用有哪些
  10. centos7服务器如何通过trunk模式接入交换机
  11. C++17 关键新特性介绍及代码讲解 (6) — fold expression
  12. android qq聊天图片无法显示,QQ聊天时无法打开图片
  13. O(lg p)计算n^p
  14. 【维修】【硬件】【苹果】wifi芯片被加密
  15. 【深度学习Faster-RCNN】深刻解读Faster R-CNN
  16. Oracle AWR 阙值影响历史执行计划
  17. 超好用的网站推荐(持续更新)
  18. SONY的IMX500浅谈
  19. 搜索引擎优化(SEO),通向成功十步
  20. 5000词学英语——DAY4

热门文章

  1. CRM WebClient UI outbound plug的使用
  2. SAP UI5是如何从浏览器读取语言设置并按照优先级排序的
  3. java试题汇编_JAVA面试题汇编 - DotNet and J2EE Developer - BlogJava
  4. mysql 集群备份脚本_mysqldump结合脚本的备份方案
  5. Jmeter5.3(windows下)安装过程问题总结
  6. tplink 跨路由器 共享打印机_焦作联通案例分享:跨网段通过防火墙共享打印机设置...
  7. python的实例属性和静态属性表_Python:类属性,实例属性,私有属性与静态方法,类方法,实例方法...
  8. mysql获取多张表中的数据_mysql 之多表查询
  9. 中原工学院c语言期末考试题,中原工学院软件学院 2010年C语言 试卷A
  10. mongoose如何发送html页面,javascript – 如何将HTML插入Mongodb?