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/.如果所有的文件都找不到,会进行一个内部重定向到最后一个参数. 务必确认只有最后 ...
随机推荐
- Java开发:字符串切割split函数——切割符转码注意事项
一.问题如下: 1.先对一个已有字符串进行操作,使用 ; 进行分割: //示例字符串 String string="sr1.db1.tb1.df1;sr2.db2.tb2.d ...
- pytorch 查看中间变量的梯度
pytorch 为了节省显存,在反向传播的过程中只针对计算图中的叶子结点(leaf variable)保留了梯度值(gradient).但对于开发者来说,有时我们希望探测某些中间变量(intermed ...
- CentOS7 Zookeeper 安装
集群部署 192.168.38.6 zk01192.168.38.7 zk02192.168.38.8 zk03 安装zookeeper,必须安装jdk. 1.下载 $ cd /usr/loca ...
- Rancher 部署 loonflow 工单系统
上篇文章介绍用实例主机部署:https://www.cnblogs.com/weavepub/p/11672305.html,本文采用Rancher上部署. 文章所有的文件都托管在Github:htt ...
- laravel框架中超实用的功能介绍
本篇文章给大家带来的内容是关于laravel框架中超实用的功能介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 让lumen的dd() dump()像laravel一样优雅 1 c ...
- laravel中如何执行请求
laravel中如何执行request请求?本篇文章给大家介绍关于laravel中执行请求的方法,需要的朋友可以参考一下,希望对你有所帮助. 我们先来看一下request是什么? 客户端(例如Web浏 ...
- pandas的使用(4)
pandas的使用(4)--文件读取和保存
- windows上redis的安装和配置
windows上redis的安装和配置 进入到Redis的根目录D:\Programming\Redis\Redis6379\Redis-x64-3.2.100底下操作: 配置文件启动 redis-s ...
- 集成Spring-Boot与gRPC,grpc-spring-boot-starter
项目地址:grpc-spring-boot-starter grpc是一个出身名门的RPC框架,性能高,灵活度高,支持多语言. 支持多语言,如果你的项目在使用多种语言做开发,非常推荐使用. 作为Jav ...
- 第一次有人把 5G 讲的这么简单明了
一个简单且神奇的公式 今天的故事,从一个公式开始讲起.这是一个既简单又神奇的公式.说它简单,是因为它一共只有 3 个字母.而说它神奇,是因为这个公式蕴含了博大精深的通信技术奥秘,这个星球上有无数 ...