Python Django Nginx不提供wagtail管理css/js文件

Python Django Nginx不提供wagtail管理css/js文件,python,django,wagtail,Python,Django,Wagtail,我在一台ubuntu服务器上安装了django wagtail,该服务器有一个使用NGINX和Gunicorn的域。我的CSS和JS文件位于我的目录中的静态文件夹中,但我不明白为什么Wagtail Admin CSS/JS文件没有被提供。我假设这与Wagtail管理文件不在CSS/JS文件的静态文件夹中这一事实有关。 我运行CollectStatic并将Debug设置为False Google chrome报告在管理员CSS/JS上找不到404个文件 NGINX文件的一部分 server {

我在一台ubuntu服务器上安装了django wagtail,该服务器有一个使用NGINX和Gunicorn的域。我的CSS和JS文件位于我的目录中的静态文件夹中,但我不明白为什么Wagtail Admin CSS/JS文件没有被提供。我假设这与Wagtail管理文件不在CSS/JS文件的静态文件夹中这一事实有关。 我运行CollectStatic并将Debug设置为False

Google chrome报告在管理员CSS/JS上找不到404个文件

NGINX文件的一部分

server {
        listen 443 default_server;
        listen [::]:443 default_server;

        root /home/projects/stemletics/stemletics/mysite/mysite;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name domain.com www.domain.com;

        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
                root /home/projects/stemletics/stemletics/mysite/mysite;
        }
        location / {
                include proxy_params;
                proxy_pass http://unix:/home/projects/stemletics/stemletics/mysite/mysite.sock;
        }
Base.py的相关部分

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
    os.path.join(PROJECT_DIR, 'static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'


# Wagtail settings

WAGTAIL_SITE_NAME = "mysite"

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'
from .base import *

DEBUG = False
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True

import os
SECRET_KEY = os.environ["DJANGO_SECRET_KEY_STEMLETICS"]

try:
    from .local import *
except ImportError:
    pass
Production.py

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = [
    os.path.join(PROJECT_DIR, 'static'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'


# Wagtail settings

WAGTAIL_SITE_NAME = "mysite"

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'
from .base import *

DEBUG = False
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True

import os
SECRET_KEY = os.environ["DJANGO_SECRET_KEY_STEMLETICS"]

try:
    from .local import *
except ImportError:
    pass
静态文件夹路径

root@django-manaland:/# cd home/projects/stemletics/stemletics/mysite/mysite/static/
root@django-manaland:/home/projects/stemletics/stemletics/mysite/mysite/static# lsbrand  css  fonts  img  js  scss

在nginx conf文件中,您需要指向要从中提供静态资产服务的目录。乍一看,您所拥有的看起来是正确的(尽管我不能100%确定您是否需要下面示例中的尾随斜杠;我总是保留尾随斜杠以防万一)


要获得该路径(从上面),请将ssh插入服务器,
cd
插入目录,Django的
collectstatic
函数将文件合并到目录中,然后运行
pwd
。它将返回一个路径,并确保以尾随斜杠结束(斜杠一直对我有效)

如果配置不正确,我认为您的静态目录不是
/home/projects/stemletics/stemletics/mysite/mysite
。请发布您的
设置.py
中的相关部分。在发布您的
位置/static/
时添加的请求信息应指向静态目录,即
/my/project/dir/static
。你自己的CSS/JS文件是如何被提供的是一个谜,但我认为这是因为你在HTML中手工编码了静态URL(它们也指向错误的位置)。哈哈,我的Nginx文件太乱了,不过我现在完全明白了。我的根目录和Nginx文件中的静态位置都是错误的。谢谢