Skip to content
Advertisement

URL Rewrite to Remove .php in my Nginx PHP-FPM

I setup Nginx PHP-FPM, with Centos 7, and Virtualmin control panel. I want to have all pages a SEO Friendly link without .php.

System automatically create configuration : etc/nginx/nginx.conf

And empty folder: etc/nginx/conf.d/

nginx.conf :

JavaScript

I found many information include the code below makes url working without .php But after applying that, the page just shown 404 not found page.

JavaScript

My question is, where should I insert the code above? what is completed code so it will work. May be I miss some parameter. If I must create a .conf file in etc/nginx/conf.d/ what is the complete code that i must put in the conf file?

Any help is much appreciated. (please note that My.Domain.IP.Address is replace with an IP address, and mydomain is a website domain name.).

Advertisement

Answer

My question is, where should I insert the code above?

The server block for your domain contains one location block. The other two location blocks need to be added to that same server block.

For example:

JavaScript

But conflicting server name error still exist. What is the solution?

Use nginx -T (that’s an uppercase T) to test the Nginx configuration file and view the entire configuration across all the included files. Inspect the server_name directives and identify where the duplicated name is coming from.

Just because your distribution includes include directives and directories to help organise your configuration across multiple files, you do not need to use them. Keeping the entire configuration in a single nginx.conf can be convenient for simpler servers.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement