【发布时间】:2025-12-18 14:15:01
【问题描述】:
我设法将我的 django 应用程序 docker 化。使用 docker-compose 我可以运行 django、postgresql 和 nginx,但 Nginx 无法正常运行。我可以访问我的应用程序,它工作正常,但是当我尝试连接到我的域时,总是在端口 8000 上工作。我想在 testapp.org 上运行我的应用程序,但我只能访问 testapp.org。我该如何解决这个问题?我需要在配置文件中使用哪些更改?我错过了什么吗?
码头工人撰写:
version: '3'
services:
db:
container_name: db.postgres
image: postgres:10
environment:
- POSTGRES_DB=testdb
- POSTGRES_USER=test
- POSTGRES_PASSWORD=password
ports:
- '5432:5432'
volumes:
- ./pgdata:/var/lib/postgresql/data
web:
restart: always
build: .
image: djangoapp
command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn fatihkocnet.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./fatihkocnet:/fatihkocnet
- ./config/nginx:/etc/nginx/conf.d
expose:
- "8000"
nginx:
restart: always
image: nginx:latest
ports:
- "8000:8000"
volumes:
- ./fatihkocnet:/fatihkocnet
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
nginx/test.conf
upstream web {
ip_hash;
server web:8000;
}
# portal
server {
location / {
proxy_pass http://web;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
listen 8000;
server_name testapp.org;
}
【问题讨论】: