簡體   English   中英

使用Slim Framework配置Nginx,如何保留.php網址

[英]Nginx configuration with Slim Framework, How to keep the .php url

我的服務器剛剛被提供程序清除,我沒有Nginx配置文件的備份。 我真的很幸運,現在它能工作了,現在我不知道該怎么辦。

因此,我有多個文件要做某些特定的事情,並且我在每個文件上使用Slim Framework。 這個想法是將php擴展名保留在URL上。 像這樣:

www.example.com/service.php/customer/1
www.example.com/api.php/data
www.example.com/test.php/other-data/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;
}}

正如評論中所建議的那樣,重寫URL以刪除“ .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服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM