Magento2 Nginx配置
官方文档中明确提到,推荐使用Nginx来运行Magento2. Nginx具有高负载高性能的特征,非常适合Magento2这样的程序运行,当前操作系统为Ubuntu20.04,其他系统均可参考.
We recommend configuring nginx using the nginx.conf.sample configuration file provided in the Magento installation directory and an nginx virtual host.
引用官方的话
1 创建Nginx虚拟主机
$vim /etc/nginx/sites-available/magento
2 添加配置内容
upstream fastcgi_backend {
server unix:/run/php/php7.4-fpm.sock;
}
server {
listen 80;
server_name www.magento-dev.com;
set $MAGE_ROOT /var/www/html/magento2;
include /var/www/html/magento2/nginx.conf.sample;
}
此处的nginx.conf.sample是Magento2包里默认存在的配置文件,只需要将其引入配置的虚拟主机里面即可.
3 创建软链接启用虚拟主机
$ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled
4 检查语法
$nginx -t
5 重启Nginx
$systemctl restart nginx