2014-05-14 58 views
1

我的服務器剛剛被提供者清除,而我沒有Nginx配置文件的備份。我得到它的工作非常幸運,現在我不知道該怎麼做。帶有Slim框架的Nginx配置,如何保持.php url

所以我有多個文件做一些特定的事情,我在每個文件上使用Slim框架。這個想法是保持URL的PHP​​擴展。事情是這樣的:

www.example.com/service.php/customer/1
www.example.com/api.php/data
www.example.com/test.php/other-data/ 5

有沒有人有這方面的線索?我真的忘了我之前做過的配置。

預先感謝您

+0

不是很髒嗎?你爲什麼要保留這個.php? –

+0

因爲我需要它。我在所有已發佈的應用程序中都使用該網址設置了靜態變量,所以我無法更改它。 –

+0

你也可以製作一些網址重寫來代替你的網址中的.php文件,這樣你就可以保持你的網址清潔,如果有人來自你已經發布的網站之一,他會進入頁面。這聽起來怎麼樣? –

回答

5

如果有人去這裏,我終於找到了答案。

server { 
listen 80; ## listen for ipv4; this line is default and implied 

root /usr/share/nginx/www; 
index index.html index.htm; 

# Make site accessible from http://localhost/ 
server_name localhost; 

location/{ 
} 

location /doc/ { 
    alias /usr/share/doc/; 
    autoindex on; 
    allow 127.0.0.1; 
    deny all; 
} 

location ~ [^/]\.php(/|$) { 
    fastcgi_split_path_info ^(.+?\.php)(/.*)$; 
    if (!-f $document_root$fastcgi_script_name) { 
     return 404; 
    } 
    include fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
}} 
0

正如評論所說,它可能是一個更好的主意來重寫網址,使「.PHP」被刪除:然後

你NGINX配置文件應該是這樣的:

server { 
    listen  80; 
    server_name example.org; 
    rewrite ^/(.*).php/(.*) /$1/$2 //add this line to get rid of '.php' 
} 

請參閱:http://nginx.org/en/docs/http/ngx_http_rewrite_module.html瞭解更多信息。

編輯配置後不要忘記重啓NGINX服務。

+0

我還需要做其他事情嗎?我仍然得到404。 –