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)

varn2

varn1

 

 

 

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

Copy over the following files from:

to:

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

Edit the lines to look like this:

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.

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

That’s it, you’re done.

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

  • el3ashe2

    still listen to 80 also with the new port

    what should we do?

    • Imad

      what do you want to run on port 80?

      • el3ashe2

        varnish i have nginx at 80 and apache not shown in tcp but in tcp6 it’s listen to 7080 and 7081
        now i want to move nginx to 8080 so i can run varnish before the nginx
        how to do that

        plesk ver 12.5
        Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
        tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 2956/dovecot
        tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 2956/dovecot
        tcp 0 0 93.16.172.78:80 0.0.0.0:* LISTEN 17432/nginx
        tcp 0 0 0.0.0.0:8880 0.0.0.0:* LISTEN 32095/sw-cp-serverd
        tcp 0 0 0.0.0.0:465 0.0.0.0:* LISTEN 16143/master
        tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1058/sshd
        tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 16143/master
        tcp 0 0 93.16.172.78:443 0.0.0.0:* LISTEN 17432/nginx
        tcp 0 0 0.0.0.0:8443 0.0.0.0:* LISTEN 32095/sw-cp-serverd
        tcp 0 0 0.0.0.0:4190 0.0.0.0:* LISTEN 2956/dovecot
        tcp 0 0 127.0.0.1:12768 0.0.0.0:* LISTEN 2974/psa-pc-remote
        tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 2956/dovecot
        tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 2956/dovecot
        tcp6 0 0 :::110 :::* LISTEN 2956/dovecot
        tcp6 0 0 :::143 :::* LISTEN 2956/dovecot
        tcp6 0 0 :::8880 :::* LISTEN 32095/sw-cp-serverd
        tcp6 0 0 :::465 :::* LISTEN 16143/master
        tcp6 0 0 :::21 :::* LISTEN 17310/xinetd
        tcp6 0 0 :::22 :::* LISTEN 1058/sshd
        tcp6 0 0 :::25 :::* LISTEN 16143/master
        tcp6 0 0 :::8443 :::* LISTEN 32095/sw-cp-serverd
        tcp6 0 0 :::4190 :::* LISTEN 2956/dovecot
        tcp6 0 0 :::993 :::* LISTEN 2956/dovecot
        tcp6 0 0 :::995 :::* LISTEN 2956/dovecot
        tcp6 0 0 :::7080 :::* LISTEN 17597/apache2
        tcp6 0 0 :::7081 :::* LISTEN 17597/apache2
        tcp6 0 0 :::106 :::* LISTEN 17310/xinetd
        tcp6 0 0 :::3306 :::* LISTEN 3794/mysqld

        • Tags

          service varnish stop
          edit the custom files
          make sure you edit “backend” as well as frontend.
          reconfigure-all
          service varnish start

          profit.