2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > Nginx (5):nginx URLRewrite伪静态配置

Nginx (5):nginx URLRewrite伪静态配置

时间:2019-12-05 10:51:00

相关推荐

Nginx (5):nginx URLRewrite伪静态配置

意思就是伪装一下URL,如/index.jsp?pageNum=2伪装成/2.html,这样的话,你访问/2.html其实跳转的真实地址是/index.jsp?pageNum=2

配置文件

server {listen 82;listen [::]:82;#root /var/www/web/index;#index index.html;server_name localhost;location / {rewrite ^/2.html$ /index.jsp?pageNum=2 break;proxy_pass http://192.168.xxx.xxx:8080;#try_files $uri $uri/ =404;}location ~*/(js|img|css) {root html;index index.html index.htm;}}

rewrite ^/2.html$ /index.jsp?pageNum=2 break;

^$是正则的开头和结尾标志,里面/2.heml可以换成其他的正则形式,比如

^([0-9]+).html$ /index.jsp?pageNum=$1 break;

&1表示第一个匹配上的规则,如果匹配的规则很多,可以加$2 $3等。

关于break是转发规则:

负载均衡

当然,伪静态不影响负载均衡,可以同时实现

server {listen 82;listen [::]:82;#root /var/www/web/index;#index index.html;upstream totalurl {server 192.168.xxx.xxx:8080 weight=8 break;server 192.168.yyy.yyy:8080 weight=8 break;}server_name localhost;location / {rewrite ^/2.html$ /index.jsp?pageNum=2 break;proxy_pass http://totalurl;#try_files $uri $uri/ =404;}location ~*/(js|img|css) {root html;index index.html index.htm;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。