iszjw 发表于 2015-11-16 10:54:50

LNMP环境下的nginx重写

  本文章适合于LNMP集成环境。
  集成包地址:http://lnmp.org/
  糖块是个地道的PHP程序,刚接触linux没多久,用CI框架做了点东西,需要用到重写,于是到网上各种google、百度相关nginx下的重写,资料文献倒是不少,但是真正适用的几乎没有,倒腾了一天才最终搞定,下边贴代码。
  location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_passunix:/tmp/php-cgi.sock;
fastcgi_paramPATH_INFO $fastcgi_script_name;
include fastcgi.conf;
#include pathinfo.conf;
    # 你也可以写到fastcgi_params文件中
}
  location /
    {


            if (!-e $request_filename) {


            rewrite ^/(?!index\.php|robots\.txt|static|images|js|styles)(.*)$ /index.php?$1 last;


    }
}
  搞定后重启nginx,如果是CI框架的话,在config配置里把URL路由设置为AUTO试试,$config['uri_protocol']= 'AUTO';
         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: LNMP环境下的nginx重写