How to configure extensionless-php on nginx only setup

codingmachine

Verified User
Joined
Dec 21, 2022
Messages
14
Hello!
I am attempting to set up extensionless-PHP where you can access a PHP file without the extension.
Example:
https://example.com/file.php could be accessed like https://example.com/file

Code:
location / {
        try_files $uri $uri.html $uri/ @extensionless-php;
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
    }

    location @extensionless-php {
        rewrite ^(.*)$ $1.php last;
    }

This would be the template I would need to apply, though I do not see where to apply this to a template file.

I know templates are stored in /usr/local/directadmin/data/templates/custom

But none of the Nginx files have a location / {} that I can see

Any help would be appreciated.
Thanks
 
Hello,

Should you need it only for one-two domains, then you'd better customize it in Directadmin interface without modifying NGINX templates.
 
Hi Alex,

How would I go about implementing it on a domain basis? Where would I go to add this configuration?

Thanks!
 
Sadly the first link does not apply as I am running an NGINX-only setup.

The second link seems to refer to modifying the template files, but you mentioned that is not recommended if i wanted to just apply this configuration for a single domain.

Hello,

Should you need it only for one-two domains, then you'd better customize it in Directadmin interface without modifying NGINX templates.

Where would i find the option to add this configuration within the DirectAdmin interface?
 
You will be probably surprised if you try and follow suggestions from these forums. :)

The nginx link is next to Apache on a page in Directadmin. The page describes how to find it and gives an overview.

2022-12-23 01.51.10 docs.directadmin.com d19838260420.png


A nginx block in DIrectAdmin is duplicating functionality of Apache blocks. The only difference is in directives (configuration file).

2022-12-23 01.53.07 docs.directadmin.com e4954420857c.png



The both links provided earlier are valid and contain replies to your questions.
 
You will be probably surprised if you try and follow suggestions from these forums. :)

The nginx link is next to Apache on a page in Directadmin. The page describes how to find it and gives an overview.

View attachment 6275

A nginx block in DIrectAdmin is duplicating functionality of Apache blocks. The only difference is in directives (configuration file).

View attachment 6276


The both links provided earlier are valid and contain replies to your questions.
Apologies!
Totally missed that. That was exactly what I was looking for.

Thanks!
 
Back
Top