[英]Nginx serve custom css file
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. 可以说,我有一个位置
/user/username/custom/custom.css
我想将此位置/user/(.*)/custom/
服务器到我不知道的位置/var/www/custom
编写NginX规则。 I tried 我试过了
location ~* /user/(.*)/custom/ {
alias /var/www/custom/;
}
but such rule doesn't work. 但是这样的规则不起作用。
Any suggestions please? 有什么建议吗? Thank you
谢谢
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 我的前2个会给404,最后一个会给您适当的文件
Ok, so finally I figured it out. 好的,所以最后我明白了。 The right solution (at least I hope so) is
正确的解决方案(至少我希望如此)是
location ~* /user/(.*)/custom/(.*) {
alias /var/www/custom/$2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.