安卓系统

配置magento 2以在centos 7上使用清漆

How to install Magento 2.3 on Ubuntu with Nginx, PHP 7.2, MySQL 5.7

How to install Magento 2.3 on Ubuntu with Nginx, PHP 7.2, MySQL 5.7

目录:

Anonim

页面速度或加载时间对于在线商店的成功至关重要。 加载时间是特定页面上的内容加载所花费的总时间。 加载时间越长,转换率越低。 这也是Google考虑确定搜索引擎排名的最重要因素之一。

在第一篇文章中,我们在CentOS 7机器上安装了Magento 2。 在本系列的第二篇文章中,我们将介绍安装和配置Varnish,以使我们的Magento商店超快速。

先决条件

确保已按照第一篇文章中的说明进行操作,并且已启用 EPEL 存储库。

怎么运行的

Varnish不支持SSL,因此我们需要使用其他服务作为SSL终止代理,在本例中为Nginx。

当访问者通过 HTTPS 在端口 443 上打开您的网站时,该请求将由Nginx处理,该代理将作为代理并将请求传递给Varnish(在端口80上)。 Varnish检查是否缓存了请求。 如果已缓存,Varnish会将缓存的数据返回给Nginx,而无需请求Magento应用程序。 如果未缓存请求,Varnish会将请求传递到端口 8080 上的Nginx,该端口将从Magento提取数据,Varnish将缓存响应。

如果访问者在端口 80 上打开没有 SSL 的网站,那么Varnish会将其重定向到URL 443 URL上的 HTTPS

配置Nginx

我们需要编辑在第一篇文章中创建的Nginx服务器块,以处理SSL / TLS终止并作为Varnish的后端。

/etc/nginx/conf.d/example.com.conf

upstream fastcgi_backend { server unix:/run/php-fpm/magento.sock; } server { listen 127.0.0.1:8080; server_name example.com www.example.com; set $MAGE_ROOT /opt/magento/public_html; set $MAGE_MODE developer; # or production include snippets/letsencrypt.conf; include /opt/magento/public_html/nginx.conf.sample; } server { listen 443 ssl http2; server_name www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; include snippets/ssl.conf; return 301 https://example.com$request_uri; } server { listen 443 ssl http2; server_name example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; include snippets/ssl.conf; access_log /var/log/nginx/example.com-access.log; error_log /var/log/nginx/example.com-error.log; location / { proxy_pass http://127.0.0.1; 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 X-Forwarded-Proto https; proxy_set_header X-Forwarded-Port 443; } }

我们还需要从 nginx.conf 文件中删除默认的Nginx服务器块。 注释或删除以下几行:

/etc/nginx/nginx.conf

… # server { # listen 80 default_server; # listen:80 default_server; # server_name _; # root /usr/share/nginx/html; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # }…

重新加载Nginx服务以使更改生效:

sudo systemctl reload nginx

安装和配置光油

Varnish是一种快速的反向代理HTTP加速器,它位于我们的Web服务器之前,将用作Magento安装的 Full Page Cache 解决方案。

使用以下命令通过yum安装Varnish:

sudo yum install varnish

要将Magento配置为使用Varnish,请运行:

php /opt/magento/public_html/bin/magento config:set --scope=default --scope-code=0 system/full_page_cache/caching_application 2

接下来,我们需要生成一个Varnish配置文件:

sudo php /opt/magento/public_html/bin/magento varnish:vcl:generate > /etc/varnish/default.vcl

上面的命令需要以root或具有sudo特权的用户身份运行, /etc/varnish/default.vcl 使用默认值( localhost 为后端主机,端口 8080 为后端端口)创建文件 /etc/varnish/default.vcl

默认配置附带的健康检查文件URL错误。 打开 default.vcl 文件,并从以黄色突出显示的行中删除 /pub 部分:

/etc/varnish/default.vcl

….probe = { #.url = "/pub/health_check.php";.url = "/health_check.php";.timeout = 2s;.interval = 5s;.window = 10;.threshold = 5; }…

默认情况下,Varnish监听端口 6081 ,我们需要将其更改为 80

/etc/varnish/varnish.params

VARNISH_LISTEN_PORT=80

完成修改后,启动并启用Varnish服务:

sudo systemctl enable varnish sudo systemctl start varnish

您可以使用 varnishlog 工具查看实时Web请求并调试Varnish。

结论

在本教程中,我们向您展示了如何通过将Varnish实现为全页缓存来加速Magento实例。

magento电子商务centos清漆

这篇文章是如何在CentOS 7系列上安装和配置Magento 2的一部分。

本系列的其他文章:

•在CentOS 7上安装Magento 2•将Magento 2配置为在CentOS 7上使用Varnish