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 指令的更多相关文章

  1. nginx proxy_pass指令’/’注意事项

    1. proxy_pass配置说明 不带/ location /test/ { proxy_pass http://t6:8300; } 带/ location /test/ { proxy_pass ...

  2. nginx的反向代理proxy_pass指令

    1. 首先什么是代理服务器?客户机发送请求时,不会直接发送到目的主机,而是先被代理服务器收到,代理服务器收到客服机的请求后,再向目的机发出,目的机就会返回数据给客户机,在返回给客户机之前,会被代理服务 ...

  3. Nginx 配置指令location 匹配符优先级和安全问题【转】

    Nginx配置指令location匹配符优先级和安全问题 使用nginx 很久了,它的性能高,稳定性表现也很好,得到了很多人的认可.特别是它的配置,有点像写程序一样,每行命令结尾一个";&q ...

  4. Nginx 配置指令的执行顺序(五)

    Nginx 的 content 阶段是所有请求处理阶段中最为重要的一个,因为运行在这个阶段的配置指令一般都肩负着生成“内容”(content)并输出 HTTP 响应的使命.正因为其重要性,这个阶段的配 ...

  5. http_proxy_module 模块(proxy_pass 指令)

    1. proxy_pass 指令介绍 该指令属于 http_proxy_module, http_proxy_module 模块可以将请求转发到另一台服务器. 在 nginx 反向代理是,会通过 lo ...

  6. nginx 代理服务指令详解

    nginx 正向代理与反向代理说明图 超级形象说明. 正向代理指令: 1, resolver 这个用于DNS服务器的ip . DNS服务器的主要工作是进行域名解析,将域名映射为对应IP地址 resol ...

  7. nginx.conf指令注释

    nginx.conf指令注释 ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于C ...

  8. nginx log_format指令记录自定义响应头

    我们用的nginx有做过一些定制开发,为了调试方便,加了一些自定义的response header,那么如何把这个自定义头记录到日志中以便于观察呢? nginx log_format指令支持这种扩展, ...

  9. Nginx try_files 指令

    Nginx try_files 指令 按顺序检查文件是否存在,返回第一个找到的文件.结尾的斜线表示为文件夹 -$uri/.如果所有的文件都找不到,会进行一个内部重定向到最后一个参数. 务必确认只有最后 ...

随机推荐

  1. 虚拟路由冗余(VRRP)协议

    1. 前言 VRRP(Virtual Router Redundancy Protocol)协议是用于实现路由器冗余的协议,最新协议在RFC3768中定义,原来的定义RFC2338被废除,新协议相对还 ...

  2. [转载]3.5 UiPath对剪切板的介绍和使用

    一.剪切板操作的介绍 模拟用户使用剪切板操作的一种行为: 例如使用设置剪切板(SettoClipboard),从剪切板获取(GetfromClipboard)的操作 二.剪切板相关操作在UiPath中 ...

  3. google 镜像

    google 镜像 http://scholar.hedasudi.com/ http://ac.scmor.com/

  4. Qt Quick 常用元素:Textinput 与 TextEdit 文本编辑框

    一.Textinput Textinput 用于编辑一行文本,类似于 QLineEdit. font 分组属性允许你设置 Textlnput 元素所用字体的各种属性,包括字体族(family).大 小 ...

  5. Github的初始设置

    设置姓名和邮箱地址 git config --global user.name "Firstname Lastname" git config --global user.emai ...

  6. 基于Laravel框架下使用守护进程supervisor实现定时任务(毫秒)

    本篇文章给大家带来的内容是关于基于Laravel框架下使用守护进程supervisor实现定时任务(毫秒),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 公司需要实现X分钟内每隔Y秒 ...

  7. Jmeter参数化之数据库读取数据

    以读取mysql数据库为例 1.下载一个mysql驱动包,最好去mysql官网下载 下载网址:https://dev.mysql.com/downloads/connector/j/ Select O ...

  8. c#多个按钮执行同一类事件-按钮按下和弹起

    首先在Winform中添加一个Button控件,在属性里面为控件添加鼠标按下和弹起事件(不要双击按钮,在属性里面添加) 再添加其他几个按钮控件,在控件的属性里面为鼠标按下和弹起添加已定义好处理函数(M ...

  9. C#调用WebService(服务引用-xml)

    情形:做接口调用三方WebService,WebService地址外网无法访问 方案: Step1:内网环境(可访问三方WebService地址,此处地址以http://127.0.0.1/WebSe ...

  10. 简单讲解Asp.Net Core自带IOC容器ServiceCollection

    一.  理解ServiceCollection之前先要熟悉几个概念:DIP.IOC.DI.Ioc容器: 二.  接下来先简单说一下几个概念问题: 1.DIP(依赖倒置原则):六大设计原则里面一种设计原 ...