`
yishh
  • 浏览: 17707 次
  • 来自: ...
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

nginx url重写

阅读更多
location /wapstats {
  rewrite ^/wapstats/awstats/([0-9]+)/(.*)$ /awstats$1/awstats/$2 last;
}

location /awstats1 {
        proxy_redirect off;
        proxy_connect_timeout 30;
        proxy_send_timeout 30;
        proxy_read_timeout 60;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://awstats1/;
}

这段配置会将 http://172.16.3.203/wapstats/awstats/1/awstats.pl?config=yesterday

这样的URL重写为

http://172.16.3.203/awstats1/awstats/awstats.pl?config=yesterday

此时会进入 awstats1 配置。需要注意的是
    proxy_pass http://awstats1/;

在 nginx中最后有没有“/” 意义不是一样的,大多数情况下没有"/",此时会自动附加访问的contenxt,即访问
    http://172.16.3.203/wapstats 时
nginx请求真实服务时使用的url会是
    http://172.16.3.8:8080/wapstats

如果附加"/",则nginx请求真实服务时使用的url会是
    http://172.16.3.8:8080/

即不会附加上wapstats 这个contenxt。
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics