关于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 / ...
随机推荐
- 前端面试题之HTML和css-很实用的知识点
display: none; 与 visibility: hidden; 的区别 相同: 它们都能让元素不可见 区别: display:none;会让元素完全从渲染树中消失,渲染的时候不占据任何空间: ...
- An example shows several CIM-XML extension headers
The example below shows several CIM-XML extension headers for a GetClass operation on the root/cimv2 ...
- Web 之 Cookie
Cookie Cookie实际上是一小段的文本信息.客户端请求服务器,如果服务器需要记录该用户状态,就使用response向客户端浏览器颁发一个Cookie.客户端浏览器会把Cookie保存起来.当浏 ...
- tensor的复制函数torch.repeat_interleave()
1. repeat_interleave(self: Tensor, repeats: _int, dim: Optional[_int]=None) 参数说明: self: 传入的数据为tensor ...
- 20060518: Alert!
Alert Received, Shrink My Blog! 转载于:https://www.cnblogs.com/yidinghe/archive/2006/05/18/403089.html
- WSFC与DFS
WSFC里面的文件服务器群集,文件始终是一份,数据始终存放在群集磁盘中,通过群集来维持文件服务器这项服务始终持续可用,在2012之前同一时间WSFC只能有一台节点对外提供文件服务,2012开始群集引入 ...
- angular2相关
脚手架安装一个项目 1.全局安装angular脚手架 npm install -g @angular/cli 2.初始化一个文件夹 ng new my-angular-demo 3.进入文件夹 cd ...
- RxJava2源码解析(二)
title: RxJava2源码解析(二) categories: 源码解析 tags: 源码解析 rxJava2 前言 本篇主要解析RxJava的线程切换的原理实现 subscribeOn 首先, ...
- JavaScript实现选择排序
一.选择排序简介 **冒泡排序.插入排序.选择排序合称为简单排序.**下面是选择排序的思想: 假设有一个数组a,我们想象成有一个班级名叫a班,现在全班随意排成一排,排头的位置是a[0],排尾的位置是a ...
- centos6.5宽带拨号上网
CentOS6以后要安装rp-pppoe这个软件,centos之前的版本是adsl-setup命令安装. (1)查看是否安装 #rpm -qa|grep rp-pppoe 没有内容输出则没安装,若可以 ...