nginx proxy_pass 指令
nginx proxy_pass 指令
文档
Nginx 官方文档
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Nginx 服务器的反向代理 proxy_pass 配置方法讲解
https://www.cnblogs.com/lianxuan1768/p/8383804.html
Syntax: proxy_pass URL;
Default: —
Context: location, if in location, limit_except
Sets the protocol and address of a proxied server and an optional URI to which a location should be mapped. As a protocol, “http” or “https” can be specified. The address can be specified as a domain name or IP address, and an optional port:
A request URI is passed to the server as follows:
# 如果 proxy_pass 指令指定了 URI ,则传给服务器的请求的 URI 中匹配 location 指令的部分将被去除掉。
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/;
}
# 如果 proxy_pass 指令没有指定 URI ,则传给服务器的请求的 URI 被原样传递。
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;
}
测试应用的目录结构
[root@localhost ~]# tree ROOT
ROOT
├── proxy
│ ├── mozq
│ │ └── test.html
│ ├── mozqtest.html
│ └── test.html
└── test.html
请求的 url 都是 www.mozq.com/proxy/test.html
所有请求的 uri 是 /proxy/test.html
upstream tomcatserver {
server 172.17.0.3:8080;
}
server {
listen 80;
server_name www.mozq.com;
location /proxy/ {
proxy_pass http://tomcatserver/;
index index.html index.htm;
}
}
#请求
www.mozq.com/proxy/test.html
# 实际访问
/test.html
server {
listen 80;
server_name www.mozq.com;
location /proxy/ {
proxy_pass http://tomcatserver/mozq/;
index index.html index.htm;
}
}
#请求
www.mozq.com/proxy/test.html
# 实际访问
/mozq/test.html
server {
listen 80;
server_name www.mozq.com;
location /proxy/ {
proxy_pass http://tomcatserver;
index index.html index.htm;
}
}
#请求
www.mozq.com/proxy/test.html
# 实际访问
/proxy/test.html
server {
listen 80;
server_name www.mozq.com;
location /proxy/ {
proxy_pass http://tomcatserver/mozq;
index index.html index.htm;
}
}
#请求
www.mozq.com/proxy/test.html
# 实际访问
/mozqtest.html
总结
请求: www.mozq.com/proxy/test.html
请求的 URI 为: /proxy/test.html
location: /proxy/
proxy_pass: 带 URI 的情况。请求的 URI 中匹配 location 指定的部分被去除掉。请求的 URI 去除掉被 location 指令匹配的部分后为 test.html 。拼接。
http://tomcatserver/ 结果: http://tomcatserver/test.html
http://tomcatserver/mozq 结果: http://tomcatserver/mozqtest.html
http://tomcatserver/mozq/ 结果: http://tomcatserver/mozq/test.html
proxy_pass: 不带 URI 的情况。使用原请求的 URI 。拼接。
http://tomcatserver 结果: http://tomcatserver/proxy/test.html
nginx proxy_pass 指令的更多相关文章
- nginx proxy_pass指令’/’注意事项
1. proxy_pass配置说明 不带/ location /test/ { proxy_pass http://t6:8300; } 带/ location /test/ { proxy_pass ...
- nginx的反向代理proxy_pass指令
1. 首先什么是代理服务器?客户机发送请求时,不会直接发送到目的主机,而是先被代理服务器收到,代理服务器收到客服机的请求后,再向目的机发出,目的机就会返回数据给客户机,在返回给客户机之前,会被代理服务 ...
- Nginx 配置指令location 匹配符优先级和安全问题【转】
Nginx配置指令location匹配符优先级和安全问题 使用nginx 很久了,它的性能高,稳定性表现也很好,得到了很多人的认可.特别是它的配置,有点像写程序一样,每行命令结尾一个";&q ...
- Nginx 配置指令的执行顺序(五)
Nginx 的 content 阶段是所有请求处理阶段中最为重要的一个,因为运行在这个阶段的配置指令一般都肩负着生成“内容”(content)并输出 HTTP 响应的使命.正因为其重要性,这个阶段的配 ...
- http_proxy_module 模块(proxy_pass 指令)
1. proxy_pass 指令介绍 该指令属于 http_proxy_module, http_proxy_module 模块可以将请求转发到另一台服务器. 在 nginx 反向代理是,会通过 lo ...
- nginx 代理服务指令详解
nginx 正向代理与反向代理说明图 超级形象说明. 正向代理指令: 1, resolver 这个用于DNS服务器的ip . DNS服务器的主要工作是进行域名解析,将域名映射为对应IP地址 resol ...
- nginx.conf指令注释
nginx.conf指令注释 ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于C ...
- nginx log_format指令记录自定义响应头
我们用的nginx有做过一些定制开发,为了调试方便,加了一些自定义的response header,那么如何把这个自定义头记录到日志中以便于观察呢? nginx log_format指令支持这种扩展, ...
- Nginx try_files 指令
Nginx try_files 指令 按顺序检查文件是否存在,返回第一个找到的文件.结尾的斜线表示为文件夹 -$uri/.如果所有的文件都找不到,会进行一个内部重定向到最后一个参数. 务必确认只有最后 ...
随机推荐
- ZROI1153 【线上训练3】数个数
ZROI1153 [线上训练3]数个数 传送门 一道非常有意思的题,涵盖了各种知识点. 首先,很显然,这是个容斥.容斥可以过掉\(30pts\). 这里我们考虑容斥+DP. 我们令\(dp[i][j] ...
- Qt Quick 常用元素:ComboBox(下拉列表) 与 ProgressBar(进度条)
一.ComboBox ComboBox,即下拉列表框,由一个列表框和一个标签控件(或编辑控件)组成.ComboBox 的下拉列表是使用 Menu 实现的,列表内的每个条目对应一个 Menultem. ...
- jsp之el表达式jstl标签
不管是el表达式还是jstl标签最终的目的都是要消除jsp中的java代码,当然是消除显式的java代码 el表达式的出现是为了简化jsp中读取数据并写入页面的操作. el表达式的功能不多,也很好记 ...
- 使用索引别名和Rollover滚动创建索引
使用索引别名和Rollover滚动创建索引 在ElasticSearch6.3.2 集群做节点冷(warm) 热(hot) 分离中,实现了ElasticSearch集群节点的冷热分离,新创建的索引只允 ...
- Neo4j图数据库从入门到精通(转)
add by zhj: 转载时,目录没整理好,还会跳转到原文 其实RDB也可以存储多对多的关系,使用的是中间表,GDB使用的是边,RDB中的实体存储在数据表,而GDB存储在节点.两者使用的底层技术不同 ...
- 正在开发的JavaScript引擎有哪些?
正在开发的JavaScript引擎有哪些? V8,用C++编写,开放源代码,由Google丹麦开发,是Google Chrome的一部分,也用于Node.js. JavaScriptCore,开放源代 ...
- 排序算法Java代码实现(六)—— 堆排序
本片内容: 堆排序 堆排序 最大堆: 二叉堆是完全二叉树或者是近似完全二叉树, 当父结点的键值总是大于或等于任何一个子节点的键值时为最大堆.(父节点大于任何一个子节点) 算法思想: 把n个元素建立最大 ...
- CSP复赛day2模拟题
没错,我又爆零了.....先让我自闭一分钟.....so 当你忘记努力的时候,现实会用一记响亮的耳光告诉你东西南北在哪. 好了,现在重归正题: 全国信息学奥林匹克联赛(NOIP2014) 复赛模拟题 ...
- Spring常用注解之一
Spring中的常用注解 @Component 把普通 pojo 实例化到 Spring 容器中,相当于配置文件中的 泛指各种组件,就是说当我们的类不属于各种归类的时候(不属于@Controller. ...
- 在小程序中实现 Mixins 方案
摘要: 小程序开发技巧 作者:jrainlau 原文:在小程序中实现 Mixins 方案 Fundebug经授权转载,版权归原作者所有. 在原生开发小程序的过程中,发现有多个页面都使用了几乎完全一样的 ...