nginx之"/"结尾
一、配置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之"/"结尾的更多相关文章
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(一)--技术流ken
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)--技术流ken>,<Ansible常用模块介绍及使用(二)--技术流ken><Ansible剧本介绍及 ...
- CentOS7.3编译安装Nginx设置开机启动
起因 最近想玩nginx了,本来用yum -y install nginx安装也启动好了,但是买了本<Nginx高性能Web服务器详解>,我咋能辜负我的书费呢?于是我就直接ps -ef | ...
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(4)
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)–技术流ken>,<Ansible常用模块介绍及使用(二)–技术流ken><Ansible剧本介绍及使用 ...
- rewirte 规则
Nginx Rewrite Rewirte 规则也称为规则重写,主要功能是实现浏览器访问 HTTP URL 的跳转,其正则 表达式是基于 Perl 语言.通常而言,几乎所有的 WEB 服务器均可以支持 ...
- nginx配置 的话注意几点 1.错误时注意看log 2.天威证书的话,有文档按照其文档一步步配置即可;3每句话的结尾注意千万别丢掉分号
nginx配置 的话注意几点 1.错误时注意看log 2.天威证书的话,有文档按照其文档一步步配置即可:3每句话的结尾注意千万别丢掉分号:4.配置https时 其转发可以转发到http上 pass_ ...
- nginx匹配以XXX结尾的
匹配以do结尾的所有文件:如http://192.168.126.168:8080/delivery/transportPlanData.do?startRelease=2019-07-06& ...
- nginx 匹配.zip .apk 结尾的文件 直接下载
server { listen 80; server_name ok.xidd.com; index index.html index.htm index.php; root /alidata/www ...
- nginx+iis+redis+Task.MainForm构建分布式架构 之 (redis存储分布式共享的session及共享session运作流程)
本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,上一篇分享文章制作是在windows上使用的nginx,一般正式发布的时候是在linux来配 ...
- nginx源码分析之网络初始化
nginx作为一个高性能的HTTP服务器,网络的处理是其核心,了解网络的初始化有助于加深对nginx网络处理的了解,本文主要通过nginx的源代码来分析其网络初始化. 从配置文件中读取初始化信息 与网 ...
随机推荐
- jmeter-抓取数据库数据,循环请求1000次(变量嵌套变量)
场景:数据库返回1000个数据,用这1000个数据去做请求 数据库请求结果为: 添加while控制器 添加BeanShell 预处理程序,${__counter(FALSE,Vcount)} 为自增函 ...
- 上传下载文件到Linux服务器
转自链接:https://blog.csdn.net/drdongshiye/article/details/89430535Mac的终端是十分强大 , 可以通过命令进行上传下载下载文件夹 scp - ...
- 18.linux日志收集数据到hdfs上面
先创建一个目录 在这个job目录下创建upload.sh文件 [hadoop@node1 ~]$ pwd /home/hadoop [hadoop@node1 ~]$ mkdir job [hadoo ...
- [转帖]【架构系列】龙芯loongson简介
[架构系列]龙芯loongson简介 https://blog.csdn.net/SoaringLee_fighting/article/details/97759305 2019年07月30日 10 ...
- inxi 查看国产服务器的硬件配置信息
下载inxi 查看国产服务器的信息 https://codeload.github.com/smxi/inxi/tar.gz/3.0.35-1 注意查看命令是 ./inxi -F 2. 直接是二进制包 ...
- Mysql创建、使用循环函数
创建函数 create procedure names() begin declare i int default 0; while i < 3000 do INSERT INTO studen ...
- 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2018)
layout: post title: 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 201 ...
- scoket模块 粘包问题 tcp协议特点 重启服务器会遇到地址被占用问题
scoket()模块函数用法 import socket socket.socket(socket_family,socket_type,protocal=0) 获取tcp/ip套接字 tcpsock ...
- 作业2:java内存模型图示
参考:http://www.infoq.com/cn/minibooks/java_memory_model?utm_source=infoq&utm_campaign=user_page&a ...
- Struts简介
一.简介 Apache Struts 2最初被称为WebWork 2,它是一个简洁的.可扩展的框架,可用于创建企业级Java web应用程序.设计这个框架是为了从构建.部署.到应用程序维护方面来简化整 ...