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的源代码来分析其网络初始化. 从配置文件中读取初始化信息 与网 ...
随机推荐
- Go语言中数组的内部实现和基础功能
数组的内部实现和基础功能 因为数组是切片和映射的基础数据结构.理解了数组的工作原理,有助于理解切片和映射提供的优雅和强大的功能. 内部实现 在Go语言里,数组是一个长度固定的数据类型,用于存储一段具有 ...
- Flutter与Xamarin跨平台移动开发相比
在过去十年中,移动行业经历了巨大的增长,特别是在应用程序开发方面.据Statista报告称,全球智能手机用户超过20亿,预计到2022年底这一数字将增加到50亿以上.在这些智能手机中,近100%在三个 ...
- Compress and decompress string
You are given a string with lower case letters only. Compress it by putting the count of the letter ...
- vue 动态添加对象属性
昨天使用vue发现直接给对象添加属性,并不能触发响应更新,后来看文档发现要通过this.$set 函数动态添加才可用,eg: this.$set( obj, key, data)
- yum更新出错-解决
Total download size: 14 MIs this ok [y/d/N]: 命令里已经yum install -y了,但是还是需要选择Y,N没有自动执行,请问这个要怎么破. PS:我是在 ...
- 【原创】大叔经验分享(56)hue导出行数限制
/opt/cloudera/parcels/CDH/lib/hue/apps/beeswax/src/beeswax/conf.py # Deprecated DOWNLOAD_CELL_LIMIT ...
- JS基础_for循环练习2
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- shiro学习(三,shiro加密)
shiro加密 使用MD5加密 认证 //自定义的Realm 域 public class CustomRealmSecret extends AuthorizingRealm { @Overrid ...
- 二、maven学习
maven工程运行环境修改 例如maven自带Tomcat6,我们想使用Tomcat7 pom.xml #配置多一个Tomcat7<plugins> <plugin> < ...
- 使用JavaFX开发桌面程序(一)
使用JavaFX开发桌面程序 注:我也是JAVA FX的初学者之一,自己在学习的时候踩了许多的坑,中文英文的资料查了不少,但是觉得FX技术和其他热门技术相比,教程还是太少了.这里就尽量做一点微小的贡献 ...