I don’t think it is necessary to explain what a Varnish Cache is and how it affects the load speed of the site. At least not in this post. If you are here, I suppose that you want to know how to setup SSL in Varnish.
First, you need to understand whether it is possible to handle SSL with another service and leave communication with the server on which Varnish is installed at the default port.
Then, create a droplet on the internal network (without access from the outside), raise the environment (Varnish and other software), and attach it to the Load Balancer.
But before you start, I want to highlight that you should make sure that your hosting provider offers some solutions (Cloud Flare, etc).
Option 2
Let’s imagine that we have to raise the environment to implement the API (monolith) on Laravel Framework, and we have our own VPS with root access.
The process looks like this:
Nginx handles the 443 port, handles static assets and proxy other requests to another Varnish Cache:6081.
Varnish checks the cache, and if not then proxy request to the backend (Nginx: 81, why Nginx and not PHP I will write below), gets the result, caches, and gives Nginx.
Nginx: 81 handle requests and run PHP on 9000 port or a socket.
PHP launches Laravel… It’s no longer interesting to us, we’ve known it for a long time.
So the scheme in short:
Nninx:443->Varnish:6081->Nginx:81->PHP:9000
Why doesn’t Varnish apply directly to PHP? Because PHP-FPM does not understand Varnish requests, and you will most likely get a 503 error.
Laravel, by the way, is a good solution since they “play nice together.”
I will skip boring guides on installing LEMP and concentrate your attention on configs.
Virtualhost for Nginx: /etc/nginx/conf.d/api.myserver.com.conf
I used this template. You just have to modify the backend port.
# /etc/varnish/default.vcl
...
backend server1 { # Define one backend
.host = "127.0.0.1"; # IP or Hostname of backend
.port = "81"; # Port Nginx or whatever is listening
.max_connections = 300; # That's it
...
That’s all. Those simple maneuvers can significantly accelerate a project. I hope this little guide will help you save your time and reduce your suffering.
ISD ofron suport IT me staf të kualifikuar të gatshëm 24×7. Suporti ynë është i disponueshëm online, offline, remote, offsite dhe përmes manualeve të përdorimit dhe të administrimit. Suporti i ISD ofrohet në forma të ndryshme: të herëpashershëm, me kontratë të thjeshtë dhe me kontratë profesionale.