一、配置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. Cookie中的httponly的属性和作用

    1.什么是HttpOnly? 如果cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击,窃取cookie内容,这样就增加了cookie的安 ...

  2. git 命令 查看历史提交 git log

    怎么理解git commit 命令 git commit 相当于 我们虚拟机快照操作,每次执行commit命令 相当于对本地仓库做一次快照,保存了当时仓库的状态, git commit -m 加上的& ...

  3. SpringBoot中使用aop-测试

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

  4. [AcWing303/304]任务安排2/3

    [AcWing303]任务安排2 有 \(N\) 个任务排成一个序列在一台机器上等待执行,它们的顺序不得改变.机器会把这 \(N\) 个任务分成若干批,每一批包含连续的若干个任务.从时刻 \(0\) ...

  5. 【转帖】 解开龙芯与mips4000的关系

    -- 苏联给的套件,我们只要把电子管插上就好. -- 千万次机器,不晓得来源 DJS-130系列,16位小型机,仿造美国NOVA DJS-180系列,超级小型机,仿造美国DEC VAX, 能跑DEC的 ...

  6. DOS ftp

    C:\>ftp /? 将文件传送到运行 FTP 服务器服务(经常称为后台程序)的计算机以及将文件从该计算机传出.可以交互使用 Ftp. FTP [-v] [-d] [-i] [-n] [-g] ...

  7. mysql语句(一)

    --建表CREATE TABLE IF NOT EXISTS `runoob_tbl`( `runoob_id` INT UNSIGNED AUTO_INCREMENT, `runoob_title` ...

  8. spring-boot 使用jdk6(三)

    环境 jdk 6 tomcat 7.0.59 sts 4.4.2 maven 3.2.5 背景 由于环境限制,还在使用 JDK6,所以需要将 spring boot 进行配置,支持JDK6. 以下所有 ...

  9. extern int PASCAL

    表示声明一个变量,这个变量在其他地方已经定义,但是这里因为要使用,所以声明下. 写成下面: extern “C” int PASCAL: 说明PASCAL是在一个C文件下定义的.如果不是在C下就不用加 ...

  10. 洛谷P2622 关灯问题II (二进制枚举+bfs

    题目描述 现有n盏灯,以及m个按钮.每个按钮可以同时控制这n盏灯——按下了第i个按钮,对于所有的灯都有一个效果.按下i按钮对于第j盏灯,是下面3中效果之一:如果a[i][j]为1,那么当这盏灯开了的时 ...