user3628119
user3628119

Reputation: 357

Nginx multiple domains shared resources

I have the following folders:

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

I want domain1 and domain2 to share static files from /web/shared/ but I am having trouble creating the mapping in 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/$1;
    }        
}

This gives me 404 error.

Upvotes: 1

Views: 92

Answers (2)

user3628119
user3628119

Reputation: 357

This works

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

Upvotes: 0

Richard Smith
Richard Smith

Reputation: 49672

Define a location for URIs that begin with /assets/ (see this document for details). Use the alias directive, as the root directive cannot be used in this case (see this document for details).

For example:

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

Upvotes: 1

Related Questions