设置如下:我有一个0.0.0.0:8000
可以通过浏览器访问的Gunicorn/Django应用程序.为了提供静态文件,我将nginx作为反向代理运行./etc/nginx/nginx.conf
配置为转发请求,如下所示:
server {
location /static/ {
alias /data/www/;
}
# Proxying the connections
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://0.0.0.0:8000;
}
}
Run Code Online (Sandbox Code Playgroud)
我的docker-compose.yml
文件如下:
version: '3.3'
services:
web:
restart: always
build: ./web
expose:
- "8000"
ports:
- "8000:8000"
volumes:
- staticdata:/usr/src/app/static_files
command: gunicorn wsgi:application --workers 2 --bind 0.0.0.0:8000
depends_on:
- postgres
nginx:
restart: always
build: ./nginx
ports:
- "80:80"
- "443:443"
volumes:
- staticdata:/data/www
depends_on:
- web
postgres:
image: …
Run Code Online (Sandbox Code Playgroud)