Nginx配置proxy_pass转发的/路径问题

在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。

location ^~ /static_js/ 

proxy_cache js_cache; 
proxy_set_header Host js.test.com; 
proxy_pass http://js.test.com/
}

如上面的配置,如果请求的url是http://servername/static_js/test.html
会被代理成http://js.test.com/test.html

而如果这么配置

location ^~ /static_js/ 

proxy_cache js_cache; 
proxy_set_header Host js.test.com; 
proxy_pass http://js.test.com
}

则会被代理到http://js.test.com/static_js/test.htm

当然,我们可以用如下的rewrite来实现/的功能

location ^~ /static_js/ 

proxy_cache js_cache; 
proxy_set_header Host js.test.com; 
rewrite /static_js/(.+)$ /$1 break; 
proxy_pass http://js.test.com
}

Nginx配置proxy_pass转发的/路径问题的更多相关文章

  1. Nginx配置proxy_pass转发的/路径

    请求原地址 :http://servername/static_js/test.html location ^~ /static_js/ { proxy_cache js_cache; proxy_s ...

  2. Nginx配置proxy_pass转发/路径问题

    proxy_ignore_client_abort on; #不允许代理端主动关闭连接 upstream的负载均衡,四种调度算法 #调度算法1:轮询.每个请求按时间顺序逐一分配到不同的后端服务器,如果 ...

  3. Nginx配置proxy_pass

    nginx配置proxy_pass,需要注意转发的路径配置 1.location /test/ { proxy_pass http://t6:8300; } 2.location /test/ { p ...

  4. 记录一次 Nginx 配置 proxy_pass 后 返回404问题

    一. Nginx 配置 proxy_pass 后 返回404问题 故障解决和定位 1.1. 问题 在一次生产涉及多次转发的配置中, 需求是下面的图: 在配置好了 proxy_pass 之后,请求 ww ...

  5. nginx配置https转发到tomcat(使用自签名的证书)

    一.使用openSSL生成自签名的证书 1.生成RSA私钥 命令:openssl genrsa -des3 -out server.key 1024 说明:生成rsa私钥,des3算法,1024强度, ...

  6. Nginx配置域名转发实例

    域名:cps.45wan.com   所在阿里云主机:123.35.9.12 45wan没有在阿里云备案 67wan已经在阿里云备案 阿里云主机(假如123.35.9.12)上原来的nginx配置: ...

  7. Nginx配置proxy_pass【转载】

    在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走. 下面四种 ...

  8. nginx 配置proxy_pass URL末尾加与不加/(斜线)的区别

    nginx在配置proxy_pass的时候 URL结尾加斜线(/)与不加的区别和注意事项 假设访问路径的 /pss/bill.html 加/斜线的情况 location /pss/ { proxy_p ...

  9. nginx配置proxy_pass URL末尾加与不加/(斜线)的区别

    nginx在配置proxy_pass的时候 URL结尾加斜线(/)与不加的区别和注意事项 假设访问路径的 /pss/bill.html 加/斜线的情况 location /pss/ { proxy_p ...

随机推荐

  1. zoom作用

    转自:http://www.cnblogs.com/top5/archive/2011/07/11/2103343.html css中的zoom的作用1.检查页面的标签是否闭合不要小看这条,也许折腾了 ...

  2. 【面试题】BD

    一面: 自我介绍,简单介绍项目: /***********发现项目没什么可问的,然后开始各种基础知识o(╯□╰)o************/ 内存结构,低地址,高地址: STL底层实现,set是否有序 ...

  3. http://m.blog.csdn.net/article/details?id=8237698

    http://m.blog.csdn.net/article/details?id=8237698

  4. Python 学习笔记01

      print:直接输出 type,求类型 数据类型:字符串,整型,浮点型,Bool型     note01.py # python learning note 01   print('Hello w ...

  5. WPF DataGrid Control

    Introduction Since .NET 4.0, Microsoft is shipping a DataGrid control that provides all the basic fu ...

  6. poj2386(简单dfs)

    就是求图中有多少个水洼.对图进行dfs遍历,并把是水洼的地方全部标记.然后从下一个是水哇的地方再进行dfs. #include <cstdio> #include <iostream ...

  7. 【原】iOS学习之XMPP环境搭建

    XMPP环境搭建 1> 搭建XMPP环境需要几个辅助工具: Java Openfire 采用Java开发,因此我们需要先安装Java环境 XAMPP XAMPP(Apache+MySQL+PHP ...

  8. ccc 模拟重力 正太分布

    ball.js cc.Class({ extends: cc.Component, properties: { x_vel:{ default:0 }, y_vel:{ default:0 }, gr ...

  9. Moscow Pre-Finals Workshop 2016. National Taiwan U Selection

    A. As Easy As Possible 每个点往右贪心找最近的点,可以得到一棵树,然后倍增查询即可. 时间复杂度$O((n+m)\log n)$. #include <bits/stdc+ ...

  10. Eclipse Java注释模板设置详解,更改 ${user}和${date}

    修改MyEclipse eclipse 注释的作者名字 转自:http://www.oschina.net/question/158170_31311 在eclipse/myeclipse中,当我们去 ...