nginx下開啓pathinfo模式

我使用的一鍵安裝包是在lnmp.org下載的 其他版本的不保證通用,

找到/usr/local/nginx/conf/nginx.conf

將這一段:

location ~ [^/]\.php(/|$)
			{
				# comment try_files $uri =404; to enable pathinfo
				try_files $uri =404;
				fastcgi_pass  unix:/tmp/php-cgi.sock;
				fastcgi_index index.php;
				include fastcgi.conf;
				#include pathinfo.conf;
			}

改爲:

location ~ \.php {
                #fastcgi_pass 127.0.0.1:9000; 
                #fastcgi_pass unix:/dev/shm/php-cgi.sock; 
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
                set $real_script_name $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                set $real_script_name $1;
                set $path_info $2;
            }
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
            }


重啓nginx服務器查看成功;

還有一種方式是通過重寫url來實現pathinfo模式:

location / {
    if (!-e $request_filename){
        rewrite ^/(.*)$ /index.php?s=/$1 last;
    }
}
第二種方式理論上是對的,但是本人沒有測試成功,僅作參考


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章