How to configure a site with NGINX PHP-FPM

1

By default, your account works with PROXY NGINX mode (httpd) with Apache-LSAPI on Cloudlinux servers. For cPanel servers, default is PROXY NGINX with Apache-PHP FPM.

It is possible to activate NGINX server with PHP FPM and per domain basis also, which provides similar performance, but it brings specificities :
- htaccess has no more effects for the concerned domain, this is why there is Nginx profiles to compensate. Custom rules can be implemented too.
- the usual PHP selector will no longer work in your cPanel for the related domain, you can choose PHP version only for the concerned domain using PHP-FPM
- for CMS websites, an adapated Nginx profile must be available

You are currently in PROXY mode (httpd) by default on the profile 'YOORshop defaut'. It is to know to go back in case...

Change your nginx profile, go in your cpanel, in section 'Nginx', click on 'Nginx-Manager'

Nginx cPanel plugin

Choose your domain then click 'Configure' :

Nginx cPanel plugin

 

You see the current global configuration as shown in example in snapshot below. Here, the configuration is the default: PROXY, you see the corresponding upstream (backend) named 'httpd' (this is the internal name of the apache process), and the nginx profile applied is named 'YOORshop default '

 

Nginx PHP-FPM in cPanel

To switch to PHP, see line 'PROXY', choose 'PHP' and 'Select'

'Upstream', choose the desired PHP version for the domain
'Template' : you will have to choose the NGINX profile among those we have specially configured with our custom securities :

YOORshop default (no CMS in particular)
YOORshop Prestashop (Prestashop CMS)
YOORshop Prestashop (Prestashop CMS with microcache)
YOORshop WordPress (CMS WordPress)
YOORshop Joomla (Joomla CMS)
YOORshop Magento (Magento CMS)
YOORshop OpenCart (OpenCart CMS)
YOORshop Magento (Magento 2 CMS)

YOORshop default cloud (app using webdav)

YOORshop Prestashop-v2

Finally : 'Apply upstream configuration'

From prestashop version 1.7.2.4 and up, you must choose add a specific thing in your nginx.conf (see at bottom of this article : 'Customize Nginx configuration' or you will get many 404) regarding custom admin name. If custom admin name is admin923vegrny, you must add in your file nginx.conf this :

set $admin_dir /admin923vegrny;

Click 'Reload', you will then see 'valid' for nginx.conf if content of the file was ok

To add Nginx personal rules, see section at bottom of this article...

NB :
- If you miss a NGINX profile, contact us if needed
- The PHP version chosen in 'PHP selector' of your cPanel has no longer any effect for domains newly configured with PHP-FPM
As a result, to change the PHP version of a domain already configed with PHP-FPM, you must redo the above process and change the PHP version by beginning again by UPSTREAM. PHP-FPM with Nginx allow to choose PHP version as a per domain basis.
- some htaccess rules may not work anymore. If error or misworking after an install working, check if your htaccess file was updated, if yes it will need to translate these rules into a personnalized nginx config, see details at bottom of this article, contact us if needed...
- you can change the PHP version per domain basis (If you need a more flexible mysql remote access, and change PHP version also without Nginx, contact us)
- if you see errors with code 503, you will need to contact us to improve the PHP-FPM settings of the concerned website
Disclaimer :
We have already seen, very rare, customized php websites entirely created by a developer, that may not work with Nginx PHP-FPM due to hard coded rewrite in php code. This can be solved either by changing the code of the website, or if you precisely describe us the rules so that we can translate them into Nginx language.

Here is the list of existing templates on server ready for use with Nginx FPM :
SilverStripe
CMS Made Simple
Codeignitor
Moodle
OwnCloud
WHMCS
Laravel
Snipe-IT
Wordpress+FastCGI(microcache)
Magento+Fooman Speedster
Wordpress+WPSuperCache
Wordpress+w3tc
Wordpress+w3tc+minify
CakePHP
Drupal+Boost
Yourls Short URL
Bolt CMS
LiteCart
PicoCMS
Respond
Symfony
Yii
MediaWiki
XenForo
Chevereto v3


Customize Nginx configuration

Create a file named nginx.conf in the folder containing the files and folder of the relevant website/domain
Enter in this file what you want in the compatible language Nginx of course otherwise it will not work, examples:
redirects, cache directive, block IP...
NB : not all possible nginx functions will work, ask us for more information

Go to the 'Nginx-Manager' plugin from your cPanel, choose the domain and 'Configure'
See line 'nginx.conf' in section 'Application status'. See next line 'nginx.conf reload', hit the reload button (wait 10-30 seconds so that new settings to be in effect), you will see status 'Valid' after few seconds if all ok.

 

Example of customization :

You see a lot of visits with Java agent user in your access logs. This is not necessarily worrying because Java is used by many sites to collect data, and sometimes to repost to your advantage in the web. But, if you want to stop them, put this in your nginx.conf file:

if ($ scanners2 = 1) {

         rewrite ^ https://www.hostingfilters.com/scanners.html permanent;

}

 

To read also : 

https://support.yoorshop.hosting/knowledgebase/4056/Hosting-with-Rocket-Nginx--WProcket-plugin-and-Nginx.html-avec-nginx.html

Contact us if needed...