Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Add Custom File Extension for PHP in Nginx  (Read 3723 times)

0 Members and 1 Guest are viewing this topic.

jominj

  • Guest
Add Custom File Extension for PHP in Nginx
« on: April 04, 2014, 02:51:43 pm »
We can add custom extension for php files in Nginx. We can do this by following below steps:

 Open the /etc/nginx/nginx.conf file and locate the following lines:
Code: [Select]
location ~ .*\.php$ {
    root   /var/www/html/www.domain.com;
    if (!-f $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1;
        break;
    }
    include        fastcgi_params;
    #root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_intercept_errors off;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html/www.domain.com$fastcgi_script$
}
We can edit the first line shown above and change it as follows to add  '.ext' as the custom file extension.

Code: [Select]
location ~ .*\.php|.*\.ext$ {

Next step is to restart the Nginx server /etc/init.d/nginx restart

Now we can create a .htaccess file. Add the following line to the file, and place it under the document root.
Addhandler application/x-httpd-php .html .php .ext