默認狀況下,nginx是不支持php和path_info的,咱們須要作些配置讓它支持,關於nginx的其餘配置信息再也不復述,只來講下server中的設置。php
server{ listen 80; server_name 127.0.0.1; root /web/project; location / { index index.php; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } }
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
1. ~ \.php改成~ \.php(.*),由於要接收.php後面的參數,不能讓它被當作目錄處理。
2. 添加fastcgi_split_path_info,該參數後面需指定正則表達式,並且必需要有兩個捕獲,第一個捕獲將會從新賦值給$fastcgi_script_name,第二個捕獲將會從新賦值給$fastcgi_path_info。
3. 添加fastcgi_param PATH_INFO,值爲$fastcgi_path_info。
html