本文转载自: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

关于Nginx参数路径问题的问题的更多相关文章

  1. Nginx 参数配置相关

    Nginx参数配置相关 by:授客 QQ:1033553122 目的: 对Nginx配置的点滴学习总结,主要目的在于分析Nginx与性能相关的一些参数设置,以便性能调优时选择最优配置   环境: $ ...

  2. 查看nginx配置文件路径

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

  3. haproxy nginx 多路径

    nginx 多路径: location / { root /t/deploy/zjdev/deployedApps/zjzc-web-frontEnd/; index index.html index ...

  4. Linux下几种重启Nginx的方式,找出nginx配置文件路径和测试配置文件是否正确

    Linux下几种重启Nginx的方式,找出nginx配置文件路径和测试配置文件是否正确 目录在/etc/ngnix/conf.d下找出nginx配置文件路径和测试配置文件是否正确# /usr/sbin ...

  5. nginx目录路径重定向[转]

    如果希望域名后边跟随的路径指向本地磁盘的其他目录,而不是默认的web目录时,需要设置nginx目录访问重定向. 应用场景:dashidan.com/image自动跳转到dashidan.com/fol ...

  6. Flask中获取参数(路径,查询,请求体,请求头)

    上一篇中已经讲述了:HTTP协议向服务器传参有几种途径{ 链接 } 在Flask中同样通过这4中传参途径进行归纳: 1. URL中路径参数的获取: 拓展: # 路由参数/路径参数:http://127 ...

  7. window nginx 中文路径, 文件名乱码问题解决

    window nginx 中文路径, 文件名乱码, error, not found 此问题是由于windows系统编码与nginx编码设置不一致导致的,因此我们要统一二者的编码 nginx编码设置 ...

  8. nginx 参数详解

    nginx的http web功能     必须使用虚拟机来配置站点:每个虚拟主机使用一个server{}段来配置     非虚拟主机的配置.公共选项,需要定义在server之外,http之内      ...

  9. Nginx参数调优

    (1)nginx运行工作进程个数,一般设置cpu的核心或者核心数x2 如果不了解cpu的核数,可以top命令之后按1看出来,也可以查看/proc/cpuinfo文件 grep ^processor / ...

随机推荐

  1. CG-CTF(2)

    CG-CTF https://cgctf.nuptsast.com/challenges#Web 续上~ 第七题:单身二十年 查看源代码: 取得flag(干杯~): 本题也可通过burp抓包,查看返回 ...

  2. 十六, Oracle约束

    前言 数据的完整性用于确保数据库数据遵从一定的商业和逻辑规则,在oracle中,数据完整性可以使用约束.触发器.应用程序(过程.函数)三种方法来实现,在这三种方法中,因为约束易于维护,并且具有最好的性 ...

  3. 基于jenkins自动打包并部署Tomcat环境

    传统网站部署的流程 在运维过程中,网站部署是运维的工作之一.传统的网站部署的流程大致分为:需求分析->原型设计->开发代码->提交代码->内网部署->内网测试->确 ...

  4. 自动化部署jenkins

    jenkins下载网站 https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/ 一.配置环境 [root@localhost ~]# hostname ...

  5. 【java基础】01 计算机基础知识

    一.计算机基础知识 1. 计算机 1. 什么是计算机? 计算机在生活中的应用举例 计算机(Computer)全称:电子计算机,俗称电脑.是一种能够按照程序运行,自动.高速处理海量数据的现代化智能电子设 ...

  6. java switch用法

    为什么80%的码农都做不了架构师?>>>   Java 7中,switch的参数可以是String类型了,这对我们来说是一个很方便的改进.到目前为止switch支持这样几种数据类型: ...

  7. React-Native iOS真机调试(新版)

    2019独角兽企业重金招聘Python工程师标准>>> React-Native iOS真机调试 看到网上很多以前的文章 找到两种方法 一 修改AppDelegate 把URL的替换 ...

  8. apache、nginx配置自签名证书

    一.apache: 安装apache.ssl.openssl yum -y install httpd httpd-pear mod_ssl openssl 生成证书文件 openssl genrsa ...

  9. CentOS 7 编译错误解决方法集合

    解决 error: the HTTP XSLT module requires the libxml2/libxslt 错误 yum -y install libxml2 libxml2-dev yu ...

  10. POJ 1287 Networking 垃圾题目

    Networking Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22362   Accepted: 11372 Desc ...