2014-05-14 100 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。 –