一、配置127.0.0.1:8081的tomcat下的文件:

1、ROOT/a.html : this is ROOT page

2、ROOT/testa.html : nihao

3、ROOT/index.html : this is ROOT index page

4、test/a.html  :  this is test page

5、test/index.html  :  this is test index page

二、nginx 的server_name配置如下:

1、proxy_pass的URI不带路径:

server {

listen 80;

server_name www.test.com;

location /nihao {

proxy_pass http://127.0.0.1:8081;

index  index.html;

}

#location 后无/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/nihao/a.html

#curl http://www.test.com/nihao/a.html    因hello目录不存在

#The requested resource is not available

location /test {

proxy_pass http://127.0.0.1:8081;

index  index.html;

}

#location 后无/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/test/a.html

#curl http://www.test.com/test/a.html

#this is test page

location /hello/ {

proxy_pass http://127.0.0.1:8081;

index  index.html;

}

#location 后有/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/hello/a.html

#curl http://www.test.com/hello/     因hello目录不存在

#The requested resource is not available

location /test/ {

proxy_pass http://127.0.0.1:8081;

index  index.html;

}

#location 后有/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/test/a.html

#curl http://www.test.com/test/

#this is test index page

}

server {

listen 80;

server_name www.test1.com;

location /nihao {

proxy_pass http://127.0.0.1:8081/;

index  index.html;

}

#location 后无/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/a.html

#curl http://www.test1.com/nihao/a.html

#this is ROOT page

location /test {

proxy_pass http://127.0.0.1:8081/;

index  index.html;

}

#location 后无/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/a.html

#curl http://www.test1.com/test/a.html

#this is ROOT page

location /hello/ {

proxy_pass http://127.0.0.1:8081/;

index  index.html;

}

#location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/index.html

#curl http://www.test1.com/hello/

#this is ROOT index page

location /test/ {

proxy_pass http://127.0.0.1:8081/;

index  index.html;

}

#location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/index.html

#curl http://www.test1.com/test/

#this is ROOT index page

}

2、proxy_pass的URI带路径:

server {

listen 80;

server_name www.test.com;

location /nihao {

proxy_pass http://127.0.0.1:8081/test;

index  index.html;

}

#location 后无/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/test/a.html

#curl http://www.test.com/nihao/a.html

#this is test page

#curl http://www.test.com/nihao

#this is test index page

location /test {

proxy_pass http://127.0.0.1:8081/test;

index  index.html;

}

#location 后无/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/test//

#curl http://www.test.com/test  重定向为:http://www.test.com/test//

#指向此网址的请求无限循环重定向

location /hello/ {

proxy_pass http://127.0.0.1:8081/test;

index  index.html;

}

#location 后有/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/testa.html

#curl http://www.test.com/hello/a.html

#nihao

#curl http://www.test.com/hello/   重定向为:http://www.test.com/hello//

#指向此网址的请求无限循环重定向

location /test/ {

proxy_pass http://127.0.0.1:8081/test;

index  index.html;

}

#location 后有/   proxy_pass 后无/  代理到 http://127.0.0.1:8081/testa.html

#curl http://www.test.com/test/a.html

#nihao

#curl http://www.test.com/test/  重定向为:http://www.test.com/test//

#指向此网址的请求无限循环重定向

}

server {

listen 80;

server_name www.test1.com;

location /nihao {

proxy_pass http://127.0.0.1:8081/test/;

index  index.html;

}

#location 后无/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/a.html

#curl http://www.test1.com/nihao

#this is test index page

#curl http://www.test1.com/nihao/a.html

#this is test page

location /test {

proxy_pass http://127.0.0.1:8081/test/;

index  index.html;

}

#location 后无/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/index.html

#curl http://www.test1.com/test

#this is test index page

location /hello/ {

proxy_pass http://127.0.0.1:8081/test/;

index  index.html;

}

#location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/a.html

#curl http://www.test1.com/hello

#this is test index page

#curl http://www.test1.com/hello/a.html

#this is test page

location /test/ {

proxy_pass http://127.0.0.1:8081/test/;

index  index.html;

}

#location 后有/   proxy_pass 后有/  代理到 http://127.0.0.1:8081/test/a.html

#curl http://www.test1.com/test/a.html

#this is test page

}

三、总结:

在nginx中配置proxy_pass代理转发时,如果在proxy_pass后面的url加/,表示绝对根路径;如果没有/,表示相对路径,把匹配的路径部分也给代理走。

proxy_pass的URI带路径中如果location的不带/,最好proxy_pass也不带;

nginx之"/"结尾的更多相关文章

  1. Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(一)--技术流ken

    前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)--技术流ken>,<Ansible常用模块介绍及使用(二)--技术流ken><Ansible剧本介绍及 ...

  2. CentOS7.3编译安装Nginx设置开机启动

    起因 最近想玩nginx了,本来用yum -y install nginx安装也启动好了,但是买了本<Nginx高性能Web服务器详解>,我咋能辜负我的书费呢?于是我就直接ps -ef | ...

  3. Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(4)

    前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)–技术流ken>,<Ansible常用模块介绍及使用(二)–技术流ken><Ansible剧本介绍及使用 ...

  4. rewirte 规则

    Nginx Rewrite Rewirte 规则也称为规则重写,主要功能是实现浏览器访问 HTTP URL 的跳转,其正则 表达式是基于 Perl 语言.通常而言,几乎所有的 WEB 服务器均可以支持 ...

  5. nginx配置 的话注意几点 1.错误时注意看log 2.天威证书的话,有文档按照其文档一步步配置即可;3每句话的结尾注意千万别丢掉分号

    nginx配置 的话注意几点 1.错误时注意看log  2.天威证书的话,有文档按照其文档一步步配置即可:3每句话的结尾注意千万别丢掉分号:4.配置https时 其转发可以转发到http上 pass_ ...

  6. nginx匹配以XXX结尾的

    匹配以do结尾的所有文件:如http://192.168.126.168:8080/delivery/transportPlanData.do?startRelease=2019-07-06& ...

  7. nginx 匹配.zip .apk 结尾的文件 直接下载

    server { listen 80; server_name ok.xidd.com; index index.html index.htm index.php; root /alidata/www ...

  8. nginx+iis+redis+Task.MainForm构建分布式架构 之 (redis存储分布式共享的session及共享session运作流程)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,上一篇分享文章制作是在windows上使用的nginx,一般正式发布的时候是在linux来配 ...

  9. nginx源码分析之网络初始化

    nginx作为一个高性能的HTTP服务器,网络的处理是其核心,了解网络的初始化有助于加深对nginx网络处理的了解,本文主要通过nginx的源代码来分析其网络初始化. 从配置文件中读取初始化信息 与网 ...

随机推荐

  1. 基于bootstrap模态框、fakeLoader实现全局遮罩层

    一.fakeLoader.js介绍 fakeLoader.js 是轻量级的 jQuery 插件,帮助你创建动态的全屏加载掩饰微调效果,模拟页面预加载的效果. 插件下载地址:https://github ...

  2. FTL方面综述

    FTL 1.百度百科 http://baike.baidu.com/link?url=HJ94Rz2Td83V8OW-6dD_h_P8CZb9VFR6HznPDopY_SFdfXDaMriYcBm1X ...

  3. Linux第三阶段题型测试

    1.如何取得/etiantian文件的权限对应的数字内容,如-rw-r--r--为644,要求使用命令取得644或0644这样的数字. 解答: 1)最土的方法:ls -l /etiantian |cu ...

  4. SpringBoot中使用aop-测试

    面向切面编程(AOP),该种方式主要是为了弥补面向对象编程(OOP)的不足,通过配置切面以及关注点.通知等我们可以在程序的任意位置对我们的代码进行增强(执行一些代码),AOP是Spring的特性之一, ...

  5. RDP爆破方式攻击防控思路梳理

  6. 修改anocanda的channel

    http://blog.csdn.net/mtj66/article/details/57074986

  7. 脚本(bat、shell)调用conda

    官网说明:https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#using-conda-in-w ...

  8. SQLite进阶-9.别名

    我们可以暂时给表或者列重命名为另一个名字,称为别名,重命名只是临时运行时改变,不会改变数据库中的实际的名字. -- 语法 SELECT column_name AS column_alias_name ...

  9. Linux系列:之软件安装

    1.安装软件 不同的Linux版本可能使用不同的软件管理机制. RPM:使用这类命令进行安装的Linux版本有CentOS. DPKG:使用这类命令进行安装的Linux版本有Debian.Ubuntu ...

  10. Linux系列(7):入门之磁盘与文件系统管理

    1.磁盘的主要概念 下面展示一下磁盘结构图: 1.磁道 2.柱面 3.物理扇区 已经了解了这么多概念,现在总结一下 4.磁盘分区 1.概念 磁盘分区就是将磁盘划分成不同的区域. 2.分区的最小单位 早 ...