LNMP环境下的nginx重写

来源:互联网 发布:window10和mac对比 编辑:程序博客网 时间:2024/05/29 12:29

本文章适合于LNMP集成环境。

集成包地址:http://lnmp.org/

糖块是个地道的PHP程序,刚接触linux没多久,用CI框架做了点东西,需要用到重写,于是到网上各种google、百度相关nginx下的重写,资料文献倒是不少,但是真正适用的几乎没有,倒腾了一天才最终搞定,下边贴代码。

location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_param  PATH_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';

0 0
原创粉丝点击