[英]Static files not loading docker-compose, django, nginx
當我運行docker-compose up時,一切正常。 重新啟動后,我的靜態文件有問題。 所有容器都啟動了,但是在靜態文件請求下,我們得到了404。
還有一次,服務器重啟后問題開始了。 當我說: docker-compose up
一切運行正常。
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
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; } }
我的問題是通過使用docker-compose版本2文件格式決定的。 似乎差別不大,但是可以正常工作。 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
添加了版本2 ,添加了命名卷,並使用driver:local添加了卷。 弦很少,但如此痛苦。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.