问题遇到的现象和发生背景
Django本地开发环境是pycharm专业版的Django3.2.9,python版本3.8。问题如标题:部署到服务器之后前台后台的静态样式调用不出来。测试地址:a.zaimengli.com
服务器部署的相关信息如下:
setting文件
"""
………………
………………
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
……
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'zaimengli.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'libraries': { # Adding this section should work around the issue.
'staticfiles' : 'django.templatetags.static',
},
},
},
]
WSGI_APPLICATION = 'zaimengli.wsgi.application'
……
……
……
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "article/static")
MEDIA_URL = '/uploads/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/uploads')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
nginx配置文件
server
{
listen 80;
server_name a.zaimengli.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/a.zaimengli.com;
location /static/ {
root /www/wwwroot/zaimengli/article/static;
}
location /media/ {
root /www/wwwroot/zaimengli/static/uploads;
}
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
#清理缓存规则
location ~ /purge(/.*) {
proxy_cache_purge cache_one $host$1$is_args$args;
#access_log /www/wwwlogs/a.zaimengli.com_purge_cache.log;
}
#引用反向代理规则,注释后配置的反向代理将无效
include /www/server/panel/vhost/nginx/proxy/a.zaimengli.com/*.conf;
include enable-php-00.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/a.zaimengli.com.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
access_log /www/wwwlogs/a.zaimengli.com.log;
error_log /www/wwwlogs/a.zaimengli.com.error.log;
}
服务器上的文件路径如下图
反复确认过路径设置应该没有问题,而且nginx也重启过后再检验的,都是无法加载css。
请问谁能指点下问题出在哪里了吗?