一、配置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. vue-cli3 取消eslint 校验代码 真正的解决办法

    在网上找了各种办法都没解决,看了下文档就解决了 关闭vue-cli3.0 报错:eslint-disable-next-line to ignore the next line.   注意我这里是VU ...

  2. 22.把hive表中数据导入到mysql中

    先通过可视化工具链接mysql,在链接的时候用sqoop 用户登录 在数据库userdb下新建表 保存,输入表名upflow 现在我们需要把hive里面的数据通过sqoop导入到mysql里面 sqo ...

  3. Elastic Search 分布式架构分析

    1 ES分布式机制的透明隐藏特性ES本身就是一个分布式系统,就是为了处理海量数据的应用.ES隐藏了复杂的分布式机制,简化了配置和操作的复杂度.ES在现在的互联网环境中,盛行的原因,主要的核心就是分布式 ...

  4. Java 日志系统

    Java 日志系统 1. 创建日志记录器 private final Logger logger = LoggerFactory.getLogger(LoggerTest.class); 2. 打印日 ...

  5. Fix Scheduled Task Won’t Run for .BAT File

    Step 1: Check File/Folder Permissions The first step to fixing this issue is ensuring that the accou ...

  6. Redis基本数据

    Redis Redis是一个速度非常快的非关系数据库(NoSql),它可以存储键(key)与五种不同的值(value)之间的映射.可以将存储的内存的键值对数据持久化到硬盘. Redis 数据结构 Re ...

  7. dgv数据绑定后,添加行遇到过的问题并解决

    1. 当控件被数据绑定时,无法以编程方式向 DataGridView 的行集合中添加行 解决方法:((DataTable)Dgv.DataSource).Rows.Add("", ...

  8. [转载]VS2005的工程用VS2010打开后,用VS2005不能打开的解决方法

    首先,在“项目”菜单里,把项目属性“目标平台”改为框架2.0,保存退出. 然后,用记事本或用编辑文本文件的方式打开你的项目文件,后缀为.sln 第一行:把“Microsoft Visual Studi ...

  9. 题解 P2879 【[USACO07JAN]区间统计Tallest Cow】

    题目链接: https://www.luogu.org/problemnew/show/P2879 思路: 先不管最大高度,我们读入一对x,y.说明,x+1~y-1之间牛的身高都小于x,y. 然后不妨 ...

  10. 和 Python 2.x 说再见!项目移到python3

    如果你仍在使用 2.x,那么是时候将你的代码移植到 Python 3 了. 在技术的长河中,软件.工具.系统等版本的迭代本是常事,但由于使用习惯.版本的兼容性.易用性等因素,很多用户及开发者在使用或做 ...