I am a bit confused actually very much confused right not regarding varnish and configuring it. Currently I am running Magento 2 on Nginx/PHP-FPM and only SSL i.e. I am redirecting user from :80 to :443 as I only want them to access over SSL. Also right now, Magento 2 is configured for cache/page_cache and session on Redis (setup on local server). However, I want to use varnish for page cache.
1)
For this, I want to install varnish via docker using given image. I exported the default.vcl file generated from Magento Admin and placed it in /etc/varnish/default.vcl
and used following commands:
docker run -e VARNISH_CONFIG_FILE=/etc/varnish/default.vcl
--restart unless-stopped
-v /etc/varnish/default.vcl:/etc/varnish/default.vcl
-Pit --name=varnish-alpine thiagofigueiro/varnish-alpine-docker
In the default.vcl
file I configured .port = 6085
, however Varnish starts listening to port 32768
instead. It looks like its not reading my default.vcl
file.
2.
Currently Nginx is listening to 80
and 443
, and if i run varnish with 80:80
it gives me error Address already in use
in docker logs. I wanted to run varnish on port 6085
and let magento do the page caching on this port. But from what i researched, it seems as I will have to run varnish on port 80, and then my websites to listen to other port, and redirect traffic on port 80 to the port of website (proxy). Am i right? So the webserver (Nginx) will actually be running on port e.g. 8080 for HTTP, and 8082 for HTTPS, and these ports will be opened within (localhost) only not to public. But then how will varnish communicate on PORT 443?
Is it possible, that I install varnish on a separate server? Or varnish should be installed on the same server as Web server.
If I can install varnish on a separate server, then how can I make it work with nginx (on a different server).
Title: Changed the title to reflect the updated problem given below.
UPDATE:
Okay I was able to get varnish to work, but its giving "Error 503 Backend fetch failed" on www.domain.com
(home page), but works fine with any subfolder or pages e.g. www.domain.com/index.php
.
- Now my Nginx config is configured to rewrite the
/index.php/
to/
. Without Varnish, it works fine, but on Varnishdomain.com/index.php/
is working fine, butdomain.com
is giving error.
Varnish Logs for /
:
<< Request >> 33
- Begin req 32 rxreq
- Timestamp Start: 1594304417.447698 0.000000 0.000000
- Timestamp Req: 1594304417.447698 0.000000 0.000000
- VCL_use boot
- ReqStart 1.1.0.1 47738 a0
- ReqMethod GET
- ReqURL /
- ReqProtocol HTTP/1.0
- ReqHeader Host: www.domain.com
- ReqHeader X-Real-IP: 162.158.155.131
- ReqHeader X-Forwarded-For: x.x.x.x, 162.158.155.131
- ReqHeader X-Forwarded-Proto: https
- ReqHeader X-Forwarded-Port: 443
- ReqHeader Connection: close
- ReqHeader Accept-Encoding: gzip
- ReqHeader CF-IPCountry:
- ReqHeader CF-RAY: 5b02af62b8a4ca78-
- ReqHeader CF-Visitor: {"scheme":"https"}
- ReqHeader accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- ReqHeader user-agent:
- ReqHeader accept-language: en-us
- ReqHeader cookie: PHPSESSID=;
- ReqHeader CF-Request-ID: 03d58bf1af0c200000001
- ReqHeader CF-Connecting-IP: x.x.x.x
- ReqHeader CDN-Loop: cloudflare
- ReqUnset X-Forwarded-For: x.x.x.x, 162.158.155.131
- ReqHeader X-Forwarded-For: x.x.x.x, 162.158.155.131, 1.1.0.1
- VCL_call RECV
- ReqHeader grace: none
- ReqURL /
- ReqUnset Accept-Encoding: gzip
- ReqHeader Accept-Encoding: gzip
- VCL_return hash
- VCL_call HASH
- VCL_return lookup
- VCL_call MISS
- VCL_return fetch
- Link bereq 34 fetch
- Timestamp Fetch: 1594304417.448049 0.000351 0.000351
- RespProtocol HTTP/1.1
- RespStatus 503
- RespReason Backend fetch failed
- RespHeader Date: Thu, 09 Jul 2020 14:20:17 GMT
- RespHeader Server: Varnish
- RespHeader content-type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- RespHeader X-Varnish: 33
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish (Varnish/6.4)
- VCL_call DELIVER
- RespUnset Age: 0
- RespHeader Pragma: no-cache
- RespHeader Expires: -1
- RespHeader Cache-Control: no-store, no-cache, must-revalidate, max-age=0
- RespUnset Server: Varnish
- RespUnset X-Varnish: 33
- RespUnset Via: 1.1 varnish (Varnish/6.4)
- VCL_return deliver
- Timestamp Process: 1594304417.448084 0.000386 0.000035
- Filters
- RespHeader Content-Length: 279
- RespHeader Connection: close
- Timestamp Resp: 1594304417.448153 0.000455 0.000068
- ReqAcct 1428 0 1428 264 279 543
- End
* << Session >> 32
- Begin sess 0 HTTP/1
- SessOpen 1.1.0.1 47738 a0 1.1.0.4 80 1594304417.447629 23
- Link req 33 rxreq
- SessClose REQ_CLOSE 0.001
- End
I have already added following params to varnish, but the error still exists.
-p http_resp_hdr_len=65536
-p http_resp_size=98304
UPDATE: These are my nginx and varnish configuration files.
nginx.conf: https://pastebin.com/raw/tQ9wAmEP
default.vcl: https://pastebin.com/raw/JmE5fncy