我对Nginx反向代理配置有麻烦
我在服务器上有一些带有Django网站的docker容器, 我正在尝试使用jwilder / nginx-proxy为他们服务。
我在做什么错了?
=========项目结构========
nginx代理
django_project_A
django_project_B
...与django_project_A相同
=============== nginx-proxy docker-compose.yml ==================
version: '3'
services:
nginx-proxy:
image: jwilder/nginx-proxy
restart: always
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
default:
external:
name: nginx-proxy
=============== django_project_A docker-compose.yml ==================
version: '2'
services:
nginx:
image: nginx:latest
container_name: nginx_django_project_A
ports:
- "80:8000"
volumes:
- ./src:/src
- ./src/static:/static
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: django_project_A
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn django_project_A.wsgi -b 0.0.0.0:8000"
volumes:
- ./src:/src
- ./src/static:/static
expose:
- "8000"
networks:
default:
external:
name: nginx-proxy
=============== django_project_A nginx.conf ==================
upstream web {
ip_hash;
server web:8000;
}
server {
location /static/ {
autoindex on;
alias /static/;
}
location / {
proxy_pass http://web/;
}
listen 8000;
server_name site.com;
}
=============== django_project_A Dockerfile =================
FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /config
ADD /config/requirements.txt /config/
RUN pip install -r /config/requirements.txt
RUN mkdir /src;
WORKDIR /src
答案 0 :(得分:0)
配置似乎很好,首先检查端口和连接性。
从Web容器检查是否可以在127.0.0.1:8000上telnet
,也从nginx容器检查是否可以ping web
。如果ping web
成功,请尝试telnet web:8000。
如果一切正常,请尝试在host
上进行telnet,因为它可能是主机上的防火墙阻止了传入流量。
答案 1 :(得分:0)
“ nginx-proxy docker-compose.yml”将是配置的中心,因此您可以尝试启用nginx与项目A和B之间的网络通信。您可以通过在“ nginx-proxy docker-compose.yml“:
networks:
nginx:
name: nginx
ipam:
driver: default
django_project_A:
external: true
django_project_B:
external: true