在gunicorn和nginx之前,一切都运行得很好,静态文件被提供给网站。但现在,它不再工作了。
Settings.py
STATICFILES_DIRS = [
'/root/vcrm/vcrm1/static/'
]
STATIC_ROOT = os.path.join(BASE_DIR, 'vcrm/static')
STATIC_URL = '/static/'
MEDIA_ROOT = '/root/vcrm/vcrm1/vcrm/media/'
MEDIA_URL = '/media/'
/etc/nginx/sites-available/vcrm
server {
listen 80;
server_name 195.110.58.168;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
root /root/vcrm/vcrm1/vcrm;
}
location = /media {
root /root/vcrm/vcrm1/vcrm;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
运行collectstatic时:
You have requested to collect static files at the destination
location as specified in your settings:
/root/vcrm/vcrm1/vcrm/static
This will overwrite existing files!
Are you sure you want to do this?
然后:
Found another file with the destination path 'admin/js/vendor/jquery/jquery.min.js'. It will be
ignored since only the first encountered file is collected. If this is not what you want, make sure
every static file has a unique path.
0 static files copied to '/root/vcrm/vcrm1/vcrm/static', 251 unmodified.
3条答案
按热度按时间r55awzrz1#
Nginx + Gunicorn + Django
Django项目:
服务器:install venv,requirements.txt:
服务器:安装NGINX:
服务器:Nginx配置:
服务器:设置主管:
服务器:管理员配置:
服务器:使用新进程更新supervisor:
bxgwgixi2#
1.从项目目录中运行
python manage.py collectstatic
。1.访问nginx的webserver配置文件并在配置文件中添加一个位置。
1.使用
sudo systemctl reload nginx
重新加载nginx服务器。brc7rcf03#
安装django软件包whitenoise后解决了这个问题。
我试过
staticfiles_urlpatterns
,但只有当Debug = True
在settings.py
文件中时才能工作,而你不会用于生产。无法更新nginx配置文件。