对于Magento2 自带的缓存配围 这里有推荐 varnsih 服务,速度是好的体验,为了配置好 Magento2 + nginx + varnshi 花了很多时间同时请教了身边好朋友,才得到问题的解决,中间过程不是报 503 错误,就是502错误,走了很多弯路,这里简要说明一下就行了,其实真的简单,被官方的说明与其它文档绕了很多
这里环境做了要求
CentOS 7 + Nginx 1.14 + varnish 4.05 (yum install varnish) + Magento2.25
安装好后 Magento2.25 后 就要配置 缓存方式
Stystem > Configuration > Advanced > System > Full Page Cache 这里就选 varnish 保存(按默认方式),同时下载varnish.vcl 文件
下载完后,把nginx 停止掉
vi /etc/varnish/default.vcl 将下载的文件内容替换
同时将这段注释掉
.probe = {
.url = "/pub/health_check.php";
.timeout = 2s;
.interval = 5s;
.window = 10;
.threshold = 5;
}
#systemctl restart varnish.service #启动vanishr
#netstat -tulpn
查看端口,vanish 占用的有 6081 与 6082
这里再修改网站配置规则
upstream fastcgi_backend {
server unix:/tmp/php-cgi-71.sock;
#server unix:/var/run/php/php7.1-fpm.sock;
}
server {
listen 80;
listen 127.0.0.1:8080;
server_name gocd.com.cn www.gocd.com.cn;
set $MAGE_ROOT /www/wwwroot/gocd.com.cn;
set $MAGE_MODE developer; # or production
include /www/wwwroot/gocd.com.cn/nginx.conf.sample;
}
server
{
listen 443 ssl http2;
server_name gocd.com.cn www.gocd.com.cn;
index index.php index.html index.htm default.php default.htm default.html;
set $MAGE_ROOT /www/wwwroot/gocd.com.cn;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
ssl_certificate /etc/letsencrypt/live/gocd.com.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/gocd.com.cn/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
location / {
proxy_pass http://127.0.0.1:6081;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Ssl-Offloaded "1";
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
#proxy_hide_header X-Varnish;
#proxy_hide_header Via;
proxy_set_header X-Forwarded-Proto $scheme;
}
access_log /www/wwwlogs/gocd.com.cn.log;
error_log /www/wwwlogs/gocd.com.cn.error.log;
}
这个是我的配置夫则
配置好后,重启nginx
再通过
varnishhits 命令可以查看到相关varnish 运行的情况