一、配置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. Linux题型

    考试题: 1.请描述下列路径的内容是做什么的? /etc/sysctlconf    --------------------------   内核配置(内核优化) /etc/rc.local    ...

  2. 自学电脑游戏第四天(Swing)

    继续之前的 3.组合框(JComboBox) 例题:利用JComboBox设计一个选择城市的程序. import java.awt.*; import javax.swing.*; public cl ...

  3. autossh

    LDAP:用old HK login SSH转发:/root/.nat_rules/opay-new root@ldap opay-new]# cat maria1-dw-60000 #!/bin/b ...

  4. DOS bcp

    C:\>bcp /?用法: bcp {dbtable | query} {in | out | queryout | format} 数据文件  [-m 最大错误数]             [ ...

  5. mybatis 基础(一) xml配置

    如果文章有误,请各位楼下评论,感谢各位积极修正! 一起学习,成为大佬! mybatis: 1.轻量级 2.高级映射(实体类与数据库表字段的映射) 这样就可以后续开发中去操作实体类而不需要去关注数据库, ...

  6. php修改替换数据库图片(文件)

    <?php extract($_POST); $date = date('Y-m-d'); $file_name = $_FILES['image']['name'];//获取缓存区图片,格式不 ...

  7. docker学习笔记之把容器commit成镜像

    docker提供了两种镜像制作的方式,提高了使用的灵活性: 1.可以将更改后的容器提交,制作成镜像(这是接下来要说明的) 2.通过Dockerfile来制作镜像 下面通过一个例子来展示方法1. 本地有 ...

  8. pidof---找寻PID

    pidof---找寻pid 1.根据守护进程找到pid [root@localhost ~]# pidof sshd 2542 1622 [root@localhost ~]# ps -ef | gr ...

  9. bat 将war文件转换成ear文件

    1.无需拷贝war文件,自动获取war set path=%path%;D:\jdk\jdk1.6.0_31\bin;C:\Program Files\7-Zip del **0001-control ...

  10. 如何使用Navicat 创建一个SqlServer定时任务

    因为网上资料不全,所以自己琢磨了一上午,终于弄出来了,记录一下. step1: 右击[函数]选择[新建函数]添加一个存储过程 step2: 选择[过程],点击下一步直至完成,然后编辑存储过程,保存 s ...