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

2024-09-30 10:40:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我用NGINX和Gunicorn在一个有域的ubuntu服务器上设置了django-wagtail。我的CSS和JS文件在我的目录中的静态文件夹中得到了正确的服务,但是我不明白为什么Wagtail管理CSS/JS文件没有被服务。我假设这与Wagtail管理文件不在CSS/JS文件所在的静态文件夹中有关。 collectRan调试设置为False。在

googlechrome报告称,在管理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;
        }

相关部分基准.py

^{pr2}$

生产.py

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

Tags: 文件djangofrom文件夹homeindexserverjs
1条回答
网友
1楼 · 发布于 2024-09-30 10:40:37

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

# your nginx site.conf file

# Site static media
location /static/ {
  # Use `pwd` to get this path, wherever your static assets are collected into
  alias /home/user/www/your_website/static_collected/; 
}

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

相关问题 更多 >

    热门问题