zoukankan      html  css  js  c++  java
  • 关于 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

  • 相关阅读:
    vim编辑器和bash算术运算入门
    vim编辑器
    egrep及文本处理工具
    grep与基本正则表达式
    bash脚本编程基础及配置文件
    博客开通了
    测试用例考虑因素
    地图测试点的总结
    app测试的case点(2)
    App 99.9%稳定
  • 原文地址:https://www.cnblogs.com/achengmu/p/11987697.html
Copyright © 2011-2022 走看看