1

My server has just wiped out by the provider, and I don't have the backup of the Nginx configuration file. It was completely lucky I got it working, now I don't know what to do.

So I am having multiple files to do some specific things, and I am using Slim Framework on each file. The idea is to keep the php extension on the URL. Something like this:

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

Does anyone have some clue on this? I really forgot what I did before with the configuration.

Thank you in advance

Didats Triadi
  • 1,502
  • 2
  • 14
  • 13
  • Isn't it dirty? Why do you want to keep this .php? – Loïc May 14 '14 at 02:45
  • because i need it. I have set static variable on all my published apps with that url, so i couldn't change it. – Didats Triadi May 14 '14 at 02:48
  • You could as well craft some url rewriting to replace .php in your urls with nothing, so that you keep your urls cleans, and if someone come from one of your already published website, he gets to the page. How does that sounds to you? – Loïc May 14 '14 at 02:53
  • Anything that works, I will be glad. Would you point out how? – Didats Triadi May 14 '14 at 02:55

2 Answers2

5

If somehow someone goes here, I finally found the answer.

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;
}}
Didats Triadi
  • 1,502
  • 2
  • 14
  • 13
0

As suggested in the comments, it's probably a better idea to rewrite your urls so that '.php' is removed :

Your NGINX configuration file should then look like this :

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

See : http://nginx.org/en/docs/http/ngx_http_rewrite_module.html for in-depth information.

Don't forget to restart your NGINX service after editing its configuration.

Loïc
  • 11,804
  • 1
  • 31
  • 49