Nginx多域共享资源

Nginx multiple domains shared resources

我有以下文件夹:

/web/domain1/  
/web/domain2/  
/web/shared/

我希望 domain1 和 domain2 共享来自 /web/shared/ 的静态文件,但我在 nginx 中创建映射时遇到问题。

domain1: /assets/  mapped to /web/shared/  
domain2: /admin/assets/ mapped to /web/shared/
server{
    server_name domain1;
    root /web/domain1/;

    location / {
        rewrite /assets/(.*) /web/shared/;
    }        
}

这给了我 404 错误。

为以 /assets/ 开头的 URI 定义 location(有关详细信息,请参阅 this document for details). Use the alias directive, as the root directive cannot be used in this case (see this document)。

例如:

location /assets/ {
    alias /web/shared/;
}

这个有效

location /assets/(.*) {
    alias /web/shared/;
}