在 Magento 2 中,您可以选择使用 Nginx 或 Apache 作为 web 服务器。以下是简单的示例配置,分别适用于 Nginx 和 Apache。

Nginx 配置示例:

server {
    listen 80;
    server_name your_domain.com www.your_domain.com;

    set $MAGE_ROOT /path/to/your/magento2;
    set $MAGE_MODE production;

    include /path/to/your/magento2/nginx.conf.sample;
}

请将 /path/to/your/magento2 替换为您 Magento 2 安装的实际路径。确保 Nginx 配置文件 /path/to/your/magento2/nginx.conf.sample 存在并包含 Magento 2 的相关配置。

Apache 配置示例:

<VirtualHost *:80>
ServerAdmin webmaster@your_domain.com
DocumentRoot "/path/to/your/magento2"
ServerName your_domain.com
ServerAlias www.your_domain.com

<Directory "/path/to/your/magento2">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog "/var/log/apache2/your_domain_error.log"
CustomLog "/var/log/apache2/your_domain_access.log" combined
</VirtualHost>

同样,请将 /path/to/your/magento2 替换为您 Magento 2 安装的实际路径。确保 Apache 的虚拟主机配置文件包含了必要的设置,如 AllowOverride All 以启用 .htaccess 文件。

在上述配置中,您需要确保 Nginx 或 Apache 的配置正确指向 Magento 2 的安装目录,并且相关的访问和错误日志路径是正确的。

此外,如果您有多个站点(Multi-Store)需要配置,请根据具体情况修改上述配置文件,并确保 Magento 2 的配置文件(如 nginx.conf.sample)中也正确设置了站点信息。

配置完成后,请重新加载或重启相应的 web 服务器,以使配置生效。