nginx rewrite proxy_pass location实践及正则匹配
来源:互联网 发布:java调用ocx控件实例 编辑:程序博客网 时间:2024/05/21 09:42
本文以IT黑名单站点为例,讲述nginx的常见配置。
前置信息:
顶层容器nginx,下面跑一个php应用监听9000端口(tucao.itblacklist.cn),一个java应用监听8000端口(www.itblacklist.cn)。
需求信息如下:
- html、js、css、jpg等静态资源尽量走nginx;
- 首页默认不带index.html 但是也走nginx;
- 前后端分离+优化url(笔者不确定这种优化是否起反作用),/s/?wd=xxx --> list.html?wd=xxx /details/{num} --> details.html?u={num}
- 其余请求转发到8000端口jetty容器(java应用);
- itblacklist.cn的请求及权重永久转到www.itblacklist.cn;
- tucao.itblacklist.cn转到php应用;
直接上配置
server {server_name www.itblacklist.cn;listen 80;root /opt/apps/blacklist/page;#nginx server根目录# =精准匹配 /首页 该规则只匹配首页location =/ {}# ~* 不区分大小写的正则匹配 匹配所有以.html .gif等结尾的请求location ~* \.(html|gif|jpg|ico|js|css|map|svg|eot|tff|woff|woff2)$ {}# ^~ 匹配以某个开头的请求 该处匹配以/s/开头的请求location ^~ /s/ {rewrite /s/(.+)$ /$1 break;proxy_pass http://www.itblacklist.cn/list.html;#... proxy头信息等}location ~* /details/([0-9]+)$ {rewrite /details/(.+)$ /details.html?u=$1 break;}location / {proxy_pass http://www.itblacklist.cn:8000;#...}}server {server_name itblacklist.cn;rewrite ^(.*)$ http://wwww.itblacklist.cn$1 permanent;}server {server_name tucao.itblacklist.cn;location / {proxy_pass http://www.itblacklist.cn:9000;#...}}
重新加载nginx配置
nginx -s reload
至此,结束。
转载请注明来源【IT黑名单】
阅读全文
0 0
- nginx rewrite proxy_pass location实践及正则匹配
- nginx rewrite proxy_pass location 的理解
- nginx rewrite proxy_pass location 的理解
- nginx详细解读location rewrite和proxy_pass
- nginx-location及rewrite
- nginx location rewrite匹配顺序
- nginx中location中关于proxy_pass和rewrite的应用
- Nginx rewrite正则匹配重写
- nginx的proxy_pass和 location为正则表达式的问题
- nginx中rewrite和proxy_pass
- nginx location节点 proxy_pass 中的”/”
- Nginx Location配置总结及rewrite
- 【Nginx】Location配置总结及rewrite
- nginx配置location及rewrite写法
- nginx,rewrite,proxy_pass,post数据,表单
- nginx location的正则匹配规则
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- Hystrix使用入门手册(中文)
- 机器人走方格
- 浅谈消息总线与消息队列的区别
- 流程图解Spring Framework(四) Spring 如何读取使用.properties
- Mysql 左连接查询条件位置不同造成数据查不出来
- nginx rewrite proxy_pass location实践及正则匹配
- 二叉堆
- 流程图解Spring Framework(五) Spring BeanFactoryPostProcessor如何工作的?
- java基础之细节补充
- Linux(centos)环境+xmanager+eclipse安装使用
- CodeForces 803A Maximal Binary Matrix-【思维+构造】
- Thinkphp5 Auth权限认证
- JSP取不到modelandview传过来的值
- 研发工程师必会的Linux命令