用thinkphp做了一個網站,部署到ubuntu上的時候需要,服務器用的是nginx,本身不支持pathinfo模式,需要修改配置文件,使其能夠用pathinfo。
我用的是虛擬主機的方式。之前配置了好久,總是出現各種各樣的問題,最後實在不行,直接用rewrite模式,配置還比較簡單。後來不知道改了什麼,rewrite也不能用了,這回打算把
pathinfo 配出來, 所以查了各種資料,一點一點的改。終於改成了。
發現很多網上的東西,其實和自己用的經常會有一點差別,需要根據自己的東西進行修改才行
server {
listen 8082;
root /usr/share/nginx/www/ssdf;
index index.php index.html index.htm;
error_page 404 /404.html; //404和後面的“/” 需要有一個空格隔開
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location / { //這裡是rewrite規則,可以單獨使用,thinkphp中模式也要改成rewrite,
if (!-e $request_filename) { //之前配置好了,不知道後來改了那不能用了。
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ ^(.+\.php)(.*) {
# try_files $uri =404; 這句只是嘗試注釋掉了,後來也沒再嘗試不注釋能不能用
# fastcgi_pass 127.0.0.1:9000; 這裡一開始寫的詞句,後來修改成default文件中的下面那一句,這句不知道這兩句怎麼用
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
# include fastcgi_params; 這裡面fastcgi_params和 fcgi.conf內容是相同的,網上兩種命名都有人用
include fcgi.conf;
set $real_script_name $fastcgi_script_name;
set $path_info "";
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){ //if語句後面一定要有個空格,要和別的區分開,屬於語法規定
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;
}
}