打開瀏覽器,然后訪問服務器,如果能夠正常訪問,並且頁面鏈接可以跳轉,但是頁面卻是亂的,那一定是nginx.conf里面的靜態文件配置不正確,
location /static/ {
#expires 30d;
#autoindex on;
#access_log off;
#add_header Cache-Control private;
root /root/project/;
}
#比如我的項目在/root/project/,這里面包含manage.py還有很多app,然后我們需要在settings.py文件增加STATIC_ROOT = os.path.join(BASE_DIR, "static"),
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder"
)
其他的不改動,然后在服務器中的/root/project/目錄新建文件夾static,運行python3 manage.py collectstatic,會將所有app中的static中的靜態文件拷貝到當前目錄static中,留作nginx使用,收集之后,我們需要重啟nginx,然后再啟動uwsgi,再訪問服務器就可以看到樣式了。