Nginx serve custom css file

215 views Asked by At

lets say, I have an location /user/username/custom/custom.css I would like to server this location /user/(.*)/custom/ to the location /var/www/custom I don't know, how to write NginX rules. I tried

location ~* /user/(.*)/custom/ {
   alias /var/www/custom/; 
}

but such rule doesn't work.

Any suggestions please? Thank you

2

There are 2 answers

0
s.t.e.a.l.t.h On

Ok, so finally I figured it out. The right solution (at least I hope so) is

location ~* /user/(.*)/custom/(.*) {
   alias /var/www/custom/$2; 
}
1
Tarun Lalwani On

Well mine was similar to this

location ~* /user/[^/]+/custom/(.*) {
   alias /var/www/custom/$1;
}

Yours suffer from the issue that below will results in the same files

/user/username/abc/test/custom/test.css
/user/username/abc/custom/test.css
/user/username/custom/test.css

Mine will give 404 on first 2 and give you the proper file on last one