简体   繁体   English

静态文件未加载docker-compose,django,nginx

[英]Static files not loading docker-compose, django, nginx

When I run docker-compose up all working good. 当我运行docker-compose up时,一切正常。 I've got problem with static file after reboot. 重新启动后,我的静态文件有问题。 All containers starts, but on static files request we got 404. 所有容器都启动了,但是在静态文件请求下,我们得到了404。

Yet another time, problems begins after server reboot. 还有一次,服务器重启后问题开始了。 When I say: docker-compose up All working perfectly. 当我说: docker-compose up一切运行正常。

docker-compose.yml docker-compose.yml

 web: restart: always build: . command: /usr/local/bin/gunicorn ems3.wsgi:application -w 2 -b :8031 volumes: - .:/code ports: - "8031:8031" links: - db nginx: restart: always build: ./nginx/ ports: - "8002:8002" # 443 - "8001:8001" # 80 volumes: - /www/static volumes_from: - web links: - web:web db: restart: always image: postgres ports: - "5555:5555" environment: - POSTGRES_PASSWORD=mysecr3333 - POSTGRES_USER=postgres 

nginx_config nginx_config

 server { listen 8002 ssl default; location /static { alias /code/static; } location / { proxy_pass http://web:8031; proxy_set_header X-Real-IP $remote_addr; #proxy_set_header Host $host:$server_port; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } 

My problems were decided by using docker-compose version 2 file format. 我的问题是通过使用docker-compose版本2文件格式决定的。 Seems little differece, but it's working. 似乎差别不大,但是可以正常工作。 docker-compose.yaml looks like this: docker-compose.yaml看起来像这样:

version: '2'
services:
  web:
    restart: always
    build: .
    command: /usr/local/bin/gunicorn proj.wsgi:application -w 2 -b :8031
    volumes:
      - web_code:/code
    ports:
      - "8031:8031"
    links:
      - db


volumes:
  web_code:
    driver: local

Added version 2 , added named volume, and added volume with driver:local. 添加了版本2 ,添加了命名卷,并使用driver:local添加了卷。 Few strings, but such painfull. 弦很少,但如此痛苦。

This is one more like me https://stackoverflow.com/a/36726663/2837890 像我这样的一个人https://stackoverflow.com/a/36726663/2837890

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

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