nginx的proxy_pass路径转发规则浅析(末尾/问题)
源地址 :
https://www.zifangsky.cn/917.html
一 location匹配路径末尾没有 /
此时proxy_pass后面的路径必须拼接location的路径:
|
1
2
3
4
5
6
7
8
|
location /sta
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.31/sta;
}
|
- 外面访问:http://192.168.1.30/sta/sta1.html
- 相当于访问:http://192.168.1.31/sta/sta1.html
注:这里也可以写成:“proxy_pass http://192.168.1.31/sta/;”。当然,不推荐使用上面这种写法
二 location匹配路径末尾有 /
此时proxy_pass后面的路径需要分为以下四种情况讨论:
(1)proxy_pass后面的路径只有域名且最后没有 /:
|
1
2
3
4
5
6
7
8
|
location /sta/
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.31;
}
|
- 外面访问:http://192.168.1.30/sta/sta1.html
- 相当于访问:http://192.168.1.31/sta/sta1.html
(2)proxy_pass后面的路径只有域名同时最后有 /:
|
1
2
3
4
5
6
7
8
|
location /sta/
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.31/;
}
|
- 外面访问:http://192.168.1.30/sta/sta1.html
- 相当于访问:http://192.168.1.31/sta1.html
(3)proxy_pass后面的路径还有其他路径但是最后没有 /:
|
1
2
3
4
5
6
7
8
|
location /sta/
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.31/abc;
}
|
- 外面访问:http://192.168.1.30/sta/sta1.html
- 相当于访问:http://192.168.1.31/abcsta1.html
(4)proxy_pass后面的路径还有其他路径同时最后有 /:
|
1
2
3
4
5
6
7
8
|
location /sta/
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.31/abc/;
}
|
- 外面访问:http://192.168.1.30/sta/sta1.html
- 相当于访问:http://192.168.1.31/abc/sta1.html
附:在nginx上面配置APK文件下载路径:
|
1
2
3
4
5
6
7
8
9
|
location ^~ /h5/appdownload/
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.31/;
proxy_set_header Cookie $http_cookie;
}
|
- 外面访问:http://test.com/h5/appdownload/Demo_1.0.0.apk
- 相当于访问:http://192.168.1.31/Demo_1.0.0.apk
每次更新apk文件,只需要上传新的apk文件到192.168.1.31服务器,然后再更新对外的下载地址为http://test.com/h5/appdownload/newName.apk即可,并不需要更改nginx的任何配置
nginx的proxy_pass路径转发规则浅析(末尾/问题)的更多相关文章
- nginx的proxy_pass路径转发规则最后带/问题
一.location匹配路径末尾没有 / location /sta{proxy_pass http://192.168.1.1/sta;} 外面访问:http://外网IP/sta/sta1.htm ...
- Nginx配置proxy_pass转发的/路径问题
Nginx配置proxy_pass转发的/路径问题 在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则 ...
- 用haproxy实现nginx的proxy_pass转发功能
公司的网站有个需求,主站点上有两个URL,没有在本地nginx上配置,而是在另一台主机的nginx上配置的站点.如果使用nginx作为反向代理,可以使用proxy_pass指令转发对这两个URL的请求 ...
- Nginx location 和 proxy_pass路径配置详解
目录 一.Nginx location 基本配置 1.1.Nginx 配置文件 1.2 .Python 脚本 二.测试 2.1.测试 location 末尾存在 / 和 proxy_pass末尾存在 ...
- Nginx配置location及rewrite规则
Nginx配置location及rewrite规则 示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } loca ...
- Nginx配置proxy_pass
nginx配置proxy_pass,需要注意转发的路径配置 1.location /test/ { proxy_pass http://t6:8300; } 2.location /test/ { p ...
- Nginx 常用全局变量 及Rewrite规则详解
每次都很容易忘记Nginx的变量,下面列出来了一些常用 $remote_addr //获取客户端ip $binary_remote_addr //客户端ip(二进制) $remote_port //客 ...
- nginx 之 proxy_pass详解
在nginx中配置proxy_pass代理转发时,如果在proxy_pass后面的url加/,表示绝对根路径:如果没有/,表示相对路径,把匹配的路径部分也给代理走. 假设下面四种情况分别用 h ...
- nginx 之 proxy_pass
nginx中有两个模块都有proxy_pass指令 ngx_http_proxy_module的proxy_pass 语法: proxy_pass URL; 场景: location, if in l ...
随机推荐
- 4.翻译系列:EF 6 Code-First默认约定(EF 6 Code-First系列)
原文地址:http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx EF 6 Code-First系列 ...
- KMP算法——从入门到懵逼到了解
本博文參考http://blog.csdn.net/v_july_v/article/details/7041827 关于其它字符串匹配算法见http://blog.csdn.net/WINCOL/a ...
- jsonp的工作原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 11款最轻量级的CSS框架
日子一去不复返了HTML用于造型的网页.今天,CSS规则,很难想象没有它的任何网页设计.CSS在最近非常先进,用于创建复杂的Web设计和风格.那么,我们为什么要使用CSS框架?答案很简单.CSS框架主 ...
- 实现div里的img图片水平垂直居中
body结构 <body> <div> <img src="1.jpg" alt="haha"> </div> ...
- PaaS 应用引擎
这里主要是梳理一下应用引擎(XXXX App Engine),它一般被归类到PaaS领域.应用引擎即提供了各种编程语言开发的应用所需的一整套运行环境:它开箱即用,你只需部署应用的代码即可,无需前期的环 ...
- Leaflet API翻译
转自: http://jsrookie.iteye.com/blog/2318972(上) http://jsrookie.iteye.com/blog/2318973(下) L.Map API各种类 ...
- modelsim 中如何加载多个对比波形文件
首先选中波形,然后点击file----datasets. 选中sim文件,然后点击save as. 对所保存的文件命名.完成之后点击done即可. 在完成上述的加载波形之后,会有多个.wlf文件,如上 ...
- oracle 11G rac 11.2.0.1 打补丁9413827
这是升级到以后11.2.0.2.11.2.0.3.11.2.0.4的基础 主要参考两篇文章: Upgrade_11.2.0.1_GI_CRS_to_11.2.0.2_in_Linux.PDF文件 ht ...
- 4. Oracle数据库用户管理备份与恢复
一. Oracle用户管理备份介绍 Oracle物理备份核心就是将物理文件拷贝一份副本:存放在磁盘上.物理文件指的是:数据文件,控制文件,日志文件,参数文件等等. 根据数据库状态而分:备份可分为热备份 ...