nginx下配置nginx.conf支持pathinfo模式

之前用的都是Apache做webserver从没碰到过pathinfo的问题,自从接触了nginx刚好项目又是用ci框架做的,刚装好就碰到pathinfo未配置导致的页面404错误。

长话短说,下面我贴上配置代码

nginx.conf中sever段配置

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name www.lnmp.org;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;
        include enable-php-pathinfo.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    error_log /home/wwwlogs/error.log error;
    }
include vhost/*.conf;
}
enable-php-pathinfo.conf 配置内容
location ~ [^/]\.php(/|$)
        {
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            set $path_info $fastcgi_path_info;
            fastcgi_param PATH_INFO       $path_info;
            try_files $fastcgi_script_name =404;
            include fastcgi.conf;
            
        }