修改配置文件nginx.conf:
静态文件报错403配置:
# 文件最上方 user nobody改为
user root owner;
404错误配置:
nginx配置文件中:
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
uwsgi_pass 127.0.0.1:8000;
include /usr/local/etc/nginx/uwsgi_params;
}
# 静态文件路径配置
location /collect_static/ {
alias /xxx/xxx/xxx/collect_static/;
}
静态配置中alias和root配置的区别为:
root响应的路径:配置的路径+完整访问路径(完整的location配置路径+静态文件)
alias响应的路径:配置路径+静态文件(去除location中配置的路径)
具体解释可查看官方文档~
Django配置文件settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'collect_static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'commen_static'),
)
STATIC_ROOT、STATICFILES_DIRS、STATIC_URL的区别可参考:https://www.cdsy.xyz/computer/programme/Python/241205/cd64786.html