Install and Configure varnish cache on Ubuntu server with VestaCP

BigDropGR

I would like to install and configure Varnish Cache to work properly on a VPS. The vps OS is Ubuntu 14.04 and I have installed and using VestaCP. Both Apache and nginx are installed on my vps.

I find no problem installing the varnish cache on the vps, my problem is that I cannot configure it to work properly. All the documentation I find is for servers using either Apache or Nginx, but VestaCP installed both on my machine. I need to move both apache and nging to some other ports and move the varnish on port 80. So, I need info on how to do that.

Thank you all.

BigDropGR

First you need to install VestaCP on your server. To do so, you need to root access your server and then type:

curl -O http://vestacp.com/pub/vst-install.sh

and

bash vst-install.sh

To install varnish, type:

sudo install varnish -y

You have to setup Varnish so it will run on port 80. The scenario will be like this: Varnish listen on port 80, Nginx on port 8082, then Apache on port 8080.

Web request = Varnish (80) -> Nginx (8082) -> Apache (8080)

Follow this steps:

  1. You mast edit the Varnish configuration file. The file is located in this directory: /etc/sysconfig/varnish (or /etc/varnish/varnish.params). You can edit through ftp by using your favourite text editor.

    nano /etc/sysconfig/varnish or nano /etc/varnish/varnish.params

  2. Search and find VARNISH_LISTEN_PORT. Change the port number to 80.

  3. Scroll down the page to find the VARNISH_STORAGE_SIZE. Set it to reasonable amount of RAM you want to allocate it as storage for the cache files made by Varnish. (All the cached files will be loaded from ram)

  4. Also change VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}" to this:VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"

  5. Save changes and exit the text editor.

  6. Configure Varnish default VCL file located in /etc/varnish/. That VCL file holds configuration to tell varnish where to look for the webserver content: /etc/varnish/default.vcl

    nano /etc/varnish/default.vcl

Here what you gonna do:

change .host ip from 127.0.0.1 to your server public IP
change .port 80 to .port 8082 which where nginx should listening.
uncomment (remove the # symbol) at sub vcl_recv section
add one } symbol at the end of that section

Find the following sub vcl_backend_response block, and add the following lines to it:

    set beresp.ttl = 10s;
    set beresp.grace = 1h;
  1. Go to /etc/nginx/conf.d/ directory and see if there is configuration file of your public IP:

    cd /etc/nginx/conf.d
    ls
    
  2. Edit that .conf file. Replace xxx.xxx.xxx.xxx with your own actual public IP:

    nano xxx.xxx.xxx.xxx.conf
    
  3. Now change port :80 to :8082

  4. Also edit vesta.conf file located at /usr/local/vesta/conf/. Use your favorite text editor or in my situation I use Nano:

    nano /usr/local/vesta/conf/vesta.conf
    

change PROXY_PORT from 80 to 8082

  1. Edit nginx.conf file for each Vesta CP user located at /home/user/conf/web. This step is quite not efficient if you have several Vesta CP users as you have to edit them all. In my example I will edit nginx.conf file for user admin:

    nano /home/admin/conf/web/nginx.conf
    

Again, change port 80 to 8082 at the listen line.

  1. Open up your favorite web browser, login to your Vesta CP dashboard as admin then click the Firewall menu on top of the page. 12.1. Edit the /WEB section of the firewall 12.2. Now ad 8082 in the Port field and hit the green Save button.

  2. Before you run a test, you have to firstly restart Nginx and start Varnish Cache server:

    service nginx restart
    service varnish start
    

I followed the instructions found on this page: http://www.servermom.org/varnish-cache-vesta-cp/2564/ http://www.servermom.org/vestacp-configuration-varnish-cache/2580/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive