关于 Nginx 配置的一些疑惑, Nginx 根据cookie 进行rewrite

网站目录结构如下:
/public/en.html
/public/zh_cn.html
/public/index.php

之前所有的非静态资源请求都交给 index.php
现在要把首页的请求 不走PHP了,提高下网站性能。Nginx会根据cookie值 lang=en 直接返回en.html 根据 lang=zh_cn 直接返回 zh_cn.html。如果没有cookie的话,默认返回 zh_cn.html.
首页请求地址有3个,分别为: 

/index
/index/index 
求Nginx 配置。
现在的Ngxin配置如下:

location / {
    index  index.php;
    if ($http_cookie ~* "lang=en"){
        rewrite ^/$ /en.html; rewrite /index /en.html; rewrite /index/index /en.html; } if ($http_cookie ~* "lang=zh_cn"){ rewrite ^/$ /zh_cn.html; rewrite /index /zh_cn.html; rewrite /index/index /zh_cn.html; } root /www/wwwroot/public; try_files $uri $uri/ /index.php?q=$uri&$args; }

但是不好使啊,网上说 location里,if 和 try_files同时使用会有问题,http://wiki.nginx.org/IfIsEvil
搞了一天了,还是没整好,好郁闷。感觉到了瓶颈了。

https://www.oschina.net/question/186778_226741

猜你喜欢

转载自www.cnblogs.com/achengmu/p/11987697.html
今日推荐