Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Change NGINX port – Plesk 12 / CentOS 6.6

We started experimenting with Varnish in a bid to tackle load instead of adding full blown replicated web server nodes. Once we were done with testing we ran into trouble implementing the set up on Plesk. There isn’t a whole lot of documentation on this matter so we ended up banging our heads on a lot of walls before we figured it out. Thankfully, though, Plesk is a lot easier and friendlier to hack than WHM/cPanel.

So, below we’ll show you how to move NGINX to a non-standard port, meaning away from port 80.

If you enter the following at shell you’ll see NGINX listening to port 80(http) and 443(https)

netstat -nlp

varn2

varn1

 

 

 

Start by heading over to the following path, create a directory called custom.

/usr/local/psa/admin/conf/templates

Copy over the following files from:

/usr/local/psa/admin/conf/templates/default

 - nginx.php
 - nginxDomainForwarding.php
 - nginxDomainForwardingIpDefault.php
 - nginxDomainVhost.php
 - nginxDomainVhostIpDefault.php
 - nginxWebmail.php

to:

/usr/local/psa/admin/conf/templates/custom

Once copied, look for the following lines in all the 6 files:

'ssl' => false,
'frontendPort' => $VAR->server->nginx->httpPort,

'ssl' => true,
'frontendPort' => $VAR->server->nginx->httpsPort,

Edit the lines to look like this:

'ssl' => false,
'frontendPort' => "8800",

'ssl' => true,
'frontendPort' => "8801",

Repeat this for all 6 files.

Run the following to regenerate config files for all domains

Note: If you have made any changes in files under /etc/php-fpm.d or /etc/nginx, they most probably will be reset. So make sure you back those up to restore them later.

/usr/local/psa/admin/bin/httpdmng --reconfigure-all

Issue the following again to verify that nothing is listening to either port 80 or 443

netstat -nlp

That’s it, you’re done.

We’ll be going over the installation and setup of Varnish in the following post.