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的源代码来分析其网络初始化. 从配置文件中读取初始化信息 与网 ...
随机推荐
- 详解vue 路由跳转四种方式 (带参数)
详解vue 路由跳转四种方式 (带参数):https://www.jb51.net/article/160401.htm 1. router-link ? 1 2 3 4 5 6 7 8 9 10 ...
- MySql查看时间
select now();命令查看MySql时间(包括时分秒) select current_date();命令查看MySql时间(不包括时分秒) 在代码中,创建时间.修改时间字段的jdbc语句也可以 ...
- 深入理解Redux之手写React-Redux
React-Redux主要由两部分组成,一是Provider(提供者),顾名思义作用就是提供状态数据. 另一部分是connect函数,它的作用是把UI组件和状态数据“连接”起来,实现了Model和Vi ...
- Ef数据GroupBy多字段查询Vb.net与c#参考
Dim g = lst.Data.GroupBy(Function(T) New With { Key T.mName, Key T.mUnit, Key T.mPrice }).Select(Fun ...
- 二、maven学习
maven工程运行环境修改 例如maven自带Tomcat6,我们想使用Tomcat7 pom.xml #配置多一个Tomcat7<plugins> <plugin> < ...
- O063、NFS Volume Provider(Part II)
参考https://www.cnblogs.com/CloudMan6/p/5693771.html 本节开始创建 NFS volume ,操作方法和 LVM volume一样,唯一的区别是在 v ...
- STM32F10xxx_Keil中添加的预定义宏
目录 STM32F10xxx_Keil中添加的预定义宏 更新记录 STM32F10xxx_Keil中添加的预定义宏 更新记录 version status description date autho ...
- Hadoop 上Hive 的操作
数据dept表的准备: --创建dept表 CREATE TABLE dept( deptno int, dname string, loc string) ROW FORMAT DELIMITED ...
- 币种大写算法(js)
注意事项:小数精度处理问题,n*10出现精度误差,如1.88*10计算得18.799999999999997,实际想要的数据是18.8: 思路一:小数变成整数(通过字符串处理),计算后,变成小数: 思 ...
- vue项目图标
项目图标iconfont 网址:http://www.iconfont.cn