简体   繁体   English

部署期间不加载静态

[英]Static are not loaded during the deploy

Static are not loaded during the deploy.部署期间不加载静态。 collectstatic was success (I see static dir with all of files on the server). collectstatic成功(我看到服务器上所有文件的静态目录)。

docker-compose.yaml version: '3.7' docker-compose.yaml 版本:'3.7'

services:
  db:
    image: postgres:12.4
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    env_file:
      - ./.env
  web:
    image: maskalev/foodgram
    restart: always
    volumes:
      - static_value:/code/static/
      - media_value:/code/media/
    depends_on:
      - db
    env_file:
      - ./.env
  nginx:
    image: nginx:1.19.3
    ports:
      - '80:80'
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      - static_value:/var/html/static/
      - media_value:/var/html/media/
    depends_on:
      - web

volumes:
  postgres_data:
  static_value:
  media_value:

nginx/default.conf nginx/default.conf

server {
    listen 80;
    server_name 127.0.0.1 x.x.x.x;
    location /static/ {
        root /var/html/;
    }
    location /media/ {
        root /var/html/;
    }
    location / {
        proxy_pass http://web:8000;
    }
}

I see messages like this:我看到这样的消息:

nginx_1  | 2021/07/30 04:55:12 [error] 28#28: *7 open() "/var/html/static/pages/indexAuth.js" failed (2: No such file or directory), client: y.y.y.y, server: 127.0.0.1, request: "GET /static/pages/indexAuth.js HTTP/1.1", host: "x.x.x.x", referrer: "http://x.x.x.x/"

Please, help me.请帮我。

Make sure you have configured STATIC_URL and STATIC_ROOT correctly.确保您已正确配置 STATIC_URL 和 STATIC_ROOT。 Please try below nginx configuration and let me know if it failed.请尝试下面的 nginx 配置,如果失败请告诉我。

server {
    listen 80;
    server_name 127.0.0.1 x.x.x.x;
    location /static/ {
        autoindex on;
        autoindex_exact_size off;
        root /var/html;
    }
    location /media/ {
        autoindex on;
        autoindex_exact_size off;
        root /var/html;
    }
    location / {
        proxy_pass http://web:8000;
    }
}

settings.py设置.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM