Nginx不会提供静态文件

问题描述 投票:0回答:2

我遵循了this教程,将我的Django项目部署在DigitalOcean上。我已经安装了Nginx和Supervisor,并且在我将settings.py中的DEBUG选项设置为False之前,所有这些都可以工作。

我尝试配置nginx.conf和settings.py百万次。将root更改为别名无济于事。

Nginx配置文件:

upstream app_server {
  server unix:/home/db1/run/gunicorn.sock fail_timeout=0;
}

server {
  listen 80;

  # add here the ip address of your server
  # or a domain pointing to that ip (like example.com or www.example.com)
  server_name ...;

  keepalive_timeout 5;
  client_max_body_size 4G;

  access_log /home/db1/logs/nginx-access.log;
  error_log /home/db1/logs/nginx-error.log;
  location /static/ {
    root /home/db1/site1/static;
  }
  # checks for static file, if not found proxy to app
  location / {
    try_files $uri @proxy_to_app;
  }

  location @proxy_to_app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://app_server;
  }
}

Settings.py

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

我遵循了本教程,将我的Django项目部署在DigitalOcean上。我已经安装了Nginx和Supervisor,并且在我将settings.py中的DEBUG选项设置为False之前,所有这些都可以工作,我试图配置...

css django nginx digital-ocean
2个回答
0
投票

非常棘手,仅根据DEBUG的状态使用这两行之一


0
投票

以下几步帮助我解决了这个问题。不确切知道哪个是实际的解决方案)

© www.soinside.com 2019 - 2024. All rights reserved.