最近在用django写软协1024的后端接口。因为用到了django自带的admin后台,所以要把后台用到的静态文件导出到static然后用nginx alias一下。代码如下:

location /static/ {
    alias /www/wwwroot/socoding1024/socoding1024/static/;
}

但是不知道为啥还是找uwsgi请求了这些静态文件,于是我就搜了下location的优先级:理论上是先匹配 ^~ 然后是从长到短(不知道为啥这个没生效)。所以加上 ^~就好了。修改后的代码如下:

location ^~ /static/ {
    alias /www/wwwroot/socoding1024/socoding1024/static/;
}
Last modification:September 22, 2022
If you think my article is useful to you, please feel free to appreciate