在 Magento 2 中,配置多站点(Multi-Store)需要特殊的 Nginx 配置,因为 Magento 2 支持在同一个安装中运行多个站点。以下是一个简单的示例,假设您有两个站点,分别是 site1.com 和 site2.com:

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

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

    include /path/to/magento2/nginx.conf.sample;
}
 
server {
    listen 80;
    server_name site2.com www.site2.com;

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

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

在这个配置中,每个 server 块对应一个站点,通过 server_name 指定了该 server 块所处理的域名。

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

Magento 2 通常附带一个名为 nginx.conf.sample 的示例配置文件,您可以在 Magento 安装目录的 pub 子目录下找到它。确保配置文件中的 fastcgi_pass 和其他相关设置正确指向您的 Magento 2 安装。

最后,确保每个域名的 DNS 记录正确指向您的服务器 IP 地址。配置完成后,重新加载或重启 Nginx 使配置生效。