关于Nginx参数路径问题的问题
本文转载自: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参数路径问题的问题的更多相关文章
- Nginx 参数配置相关
Nginx参数配置相关 by:授客 QQ:1033553122 目的: 对Nginx配置的点滴学习总结,主要目的在于分析Nginx与性能相关的一些参数设置,以便性能调优时选择最优配置 环境: $ ...
- 查看nginx配置文件路径
进入nginx安装目录(我的是/usr/local/nginx-1.7.8/) 进入sbin目录,输入 ./nginx -t查看nginx配置文件路径以及该文件语法是否正确 ./nginx -v查看n ...
- haproxy nginx 多路径
nginx 多路径: location / { root /t/deploy/zjdev/deployedApps/zjzc-web-frontEnd/; index index.html index ...
- Linux下几种重启Nginx的方式,找出nginx配置文件路径和测试配置文件是否正确
Linux下几种重启Nginx的方式,找出nginx配置文件路径和测试配置文件是否正确 目录在/etc/ngnix/conf.d下找出nginx配置文件路径和测试配置文件是否正确# /usr/sbin ...
- nginx目录路径重定向[转]
如果希望域名后边跟随的路径指向本地磁盘的其他目录,而不是默认的web目录时,需要设置nginx目录访问重定向. 应用场景:dashidan.com/image自动跳转到dashidan.com/fol ...
- Flask中获取参数(路径,查询,请求体,请求头)
上一篇中已经讲述了:HTTP协议向服务器传参有几种途径{ 链接 } 在Flask中同样通过这4中传参途径进行归纳: 1. URL中路径参数的获取: 拓展: # 路由参数/路径参数:http://127 ...
- window nginx 中文路径, 文件名乱码问题解决
window nginx 中文路径, 文件名乱码, error, not found 此问题是由于windows系统编码与nginx编码设置不一致导致的,因此我们要统一二者的编码 nginx编码设置 ...
- nginx 参数详解
nginx的http web功能 必须使用虚拟机来配置站点:每个虚拟主机使用一个server{}段来配置 非虚拟主机的配置.公共选项,需要定义在server之外,http之内 ...
- Nginx参数调优
(1)nginx运行工作进程个数,一般设置cpu的核心或者核心数x2 如果不了解cpu的核数,可以top命令之后按1看出来,也可以查看/proc/cpuinfo文件 grep ^processor / ...
随机推荐
- MVC-过滤器-异常处理
通常异常处理是用try{ }catch{ },导致代码重复冗余. 利用特性处理demo 若action中已经包含try catch 则是被异常处理过,则不会被上面异常捕获到. 不管是视图,还是调用的d ...
- [Abp vNext 入坑分享] - 4.JWT授权的接入
一.感想 在写这一系列文章之前,本来以为写这个之前已经搭建好的框架描述会比较简单,但是慢慢写下来才发现.写这个真的不简单额,本来以为图文一起,一个晚上应该能输出一篇吧...结果:现实真的骨感,一个星期 ...
- php token验证范例
<?php $module = $_GET['module']; $action = $_GET['action']; $token = md5sum($module.date('Y-m-d', ...
- Inno Setup 升级时不再询问用户安装路径
UsePreviousAppDir Description: When this directive is yes, the default, at startup Setup will look i ...
- How to change the header background color of a QTableView
You can set the style sheet on the QTableView ui->tableView->setStyleSheet("QHeaderView:: ...
- SpringCloudAlibaba实战教程系列
一.简介 Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案.此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开 ...
- ubuntu(物理机)连接ARM开发板
非虚拟机 ubuntu下连接开发板 首先安装超级终端minicom sudo apt-get install minicom 安装完minicom以后,需要将开发板和电脑进行物理连接.需要使用一条网线 ...
- 原生JS中获取位置的方案总结
获取鼠标当前位置 clientY.clientX: 鼠标当前位置 相对于 浏览器可视区域顶部.浏览器可视区域左部 的位置: pageY.pageX: 鼠标当前位置 相对于 文档顶部.文档左部的位置: ...
- 背英语单词很困难,不妨学习一下词根词缀吧(每天10个词根、词缀)Part 3
1.ir- 不,向内 例词: irregular=ir(不)-regular(规则的)=不规则的 irrigate=ir(向内)-rigate(浇水)=灌溉 2. kilo- 千 例词: kilogr ...
- Acmer 仅以此纪念最痛苦的一天
今天打比赛,完全不在状态,看到别人又AK了,自己心里真TM不是个滋味,我为什么这么弱,菜鸡,每天都在水题,我的人生也是这么水?伪学习?没有学习能力,这不只是队伍的问题,是自己的问题,别人平均3题我们队 ...