见配置,摘自nginx.conf 里的server 段:

server {
listen 80;
server_name abc.163.com ;
location / {
proxy_pass http://ent.163.com/ ;
}
location /star/ {
proxy_pass http://ent.163.com ;
}
}

里面有两个location,我先说第一个,/ 。其实这里有两种写法,分别是:

location / {
proxy_pass http://ent.163.com/ ;
}
location / {
proxy_pass http://ent.163.com ;
}

出来的效果都一样的。

第二个location,/star/。同样两种写法都有,都出来的结果,就不一样了。

location /star/ {
proxy_pass http://ent.163.com ;
}

当访问 http://abc.163.com/star/ 的时候,nginx 会代理访问到 http://ent.163.com/star/ ,并返回给我们。

location /star/ {
proxy_pass http://ent.163.com/ ;
}

当访问 http://abc.163.com/star/ 的时候,nginx 会代理访问到 http://ent.163.com/ ,并返回给我们。

这两段配置,分别在于, proxy_pass http://ent.163.com/ ; 这个”/”,令到出来的结果完全不同。

前者,相当于告诉nginx,我这个location,是代理访问到http://ent.163.com 这个server的,我的location是什么,nginx 就把location 加在proxy_pass 的 server 后面,这里是/star/,所以就相当于 http://ent.163.com/star/。如果是location /blog/ ,就是代理访问到 http://ent.163.com/blog/。

后者,相当于告诉nginx,我这个location,是代理访问到http://ent.163.com/的,http://abc.163.com/star/ == http://ent.163.com/ ,可以这样理解。改变location,并不能改变返回的内容,返回的内容始终是http://ent.163.com/ 。 如果是location /blog/ ,那就是 http://abc.163.com/blog/ == http://ent.163.com/ 。

这样,也可以解释了上面那个location / 的例子,/ 嘛,加在server 的后面,仍然是 / ,所以,两种写法出来的结果是一样的。

PS: 如果是 location ~* ^/start/(.*)\.html 这种正则的location,是不能写”/”上去的,nginx -t 也会报错的了。因为,路径都需要正则匹配了嘛,并不是一个相对固定的locatin了,必然要代理到一个server。

nginx proxy_pass 里的”/”的更多相关文章

  1. nginx proxy_pass 与 rewrite 简记

    rewrite syntax: rewrite regex replacement [flag] Default: - Context: server, location, if 如果正则表达式(re ...

  2. 统计nginx日志里流量

    用awk可以,比如,我想统计nginx日志里,今天下午3点0分,这一分钟内,访问的流量(文件的大小) grep "07/Nov/2013:15:00:"  *.log|awk '{ ...

  3. nginx proxy_pass 指令

    nginx proxy_pass 指令 文档 Nginx 官方文档 https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pa ...

  4. nginx proxy_pass

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

  5. nginx proxy_pass 代理域名

    一.描述 1.nginx配置转发的时候使用的是域名,即使用dns服务方便配置和负载.但是nginx默认会进行缓存,当域名对应的服务出问题的时候就会报错,只有默认的缓存时间到了才会再次进行解析,ngin ...

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

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

  7. 用反向代理nginx proxy_pass配置解决ie8 ajax请求被拦截问题 ie8用nginx代理实现跨域请求访问 nginx405正向代理request_uri

    最近调PC版网站ie8的兼容性,发现所有ajax请求还没到后端服务器就直接ajax error了 ie8发不出ajax请求,断点调试发现ajax全进入了error,提示“No transport” 我 ...

  8. nginx proxy_pass后的url加不加/的区别

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

  9. NGINX proxy_pass 域名解析问题

    前两天发现一个问题,当使用proxy_pass的时候,发现域名对应IP是缓存的,这样一旦VIP变化之后,就会报错,下面就来详细分析一下这个问题. 一.问题说明 location = /test { i ...

随机推荐

  1. viewflipper的高度设置

    由于ViewFlipper的一个子view是这个ImageView,ViewFilpper在切换时,高度总是为子View中高度最大的值作为其高度值. 后经搜索,发现需要设置android:measur ...

  2. How to show only next line after the matched one?

    awk '/blah/{getline; print}' logfile

  3. C++ development cross platforms

    1. target platforms: linux suse, windows server, both use vmware virtual machine on lab server. 2. c ...

  4. 隐藏服务器真实IP的方法来防止DDOS攻击

    2017-08-22 作者:小唐 点击: 10,500次 在无盘系统的环境下,服务器软件存在漏洞,就容易受到DDOS攻击,隐藏服务器真实IP是解决问题最好的方法,下面小编与大家分享一下隐藏服务器真实I ...

  5. ubuntu常用 命令

    卸载软件 ,比如chrome sudo apt-get remove google-chrome-stable

  6. httpd.conf详细解释

    httpd.conf详解  http://www.php100.com/html/webkaifa/apache/2009/0418/1192.html

  7. ylb:事务处理

    ylbtech_sqlserver --1.定义三个变量分别保存你的姓名,年龄和身高,然后赋值并且输出 --DECLARE @name varchar(10) , @age int , @height ...

  8. Java:集合类的区别详解

    Java中集合类的区别 Array是数组,不在集合框架范畴之内,一旦选定了,它的容量大小就不能改变了,所以通常在编程中不选用数组来存放. 集合 : 集合对象:用于管理其他若干对象的对象 数组:长度不可 ...

  9. osg节点统计方法(点数 面数) 【转】

    void statusNode(osg::ref_ptr<osg::Node> node,int& verNum,int& faceNum){ osg::ref_ptr&l ...

  10. c:foreach如何输出序号

    关键在于<c:forEach>的varStatus属性,具体代码如下: <table width="500" border="0" cells ...