我已经用Docker compose配置了Nginx和Gunicorn。的 问题在于,当我尝试访问主机上的https://localhost:7778时,我只得到502 Bad Gateway,这是Nginx明确提供的。 我已经证实了这种方法在没有Docker的情况下也可以使用,因此我的结论是我以某种方式弄乱了Docker配置,或者未能正确适应Docker环境。可以在下面找到配置文件,我希望有人可以找到该错误。
docker-compose.yml:
version: '3'
services:
nginx:
build: ./nginx/
container_name: examplenginx
ports:
- "7777:7777"
- "7778:7778"
depends_on:
- apiprovider
apiprovider:
build: ./apiprovider/
container_name: exampleapiprovider
expose:
- "8888"
apiprovider / Dockerfile:
FROM debian:jessie
ADD requirements.txt /
ADD setup.sh /
ADD scheme.sql /
ADD utils.py /
ADD api.py /
RUN \
apt-get update && \
apt-get install -y python3 && \
apt-get install -y python3-pip && \
python3 -m pip install --upgrade pip setuptools wheel && \
pip3 install -r requirements.txt && \
./setup.sh && \
apt-get install -y sqlite3 && \
sqlite3 users.db < scheme.sql
EXPOSE 8888
CMD ["python3", "./api.py"]
nginx / Dockerfile:
FROM debian:jessie
ADD nginxsett /
ADD service.crt /
ADD service.key /
ADD run.sh /
RUN \
apt-get update && \
apt-get install -y nginx && \
cp nginxsett /etc/nginx/sites-enabled/ && \
apt-get install openssl && \
cp service.crt /etc/nginx && \
cp service.key /etc/nginx
CMD ["nginx", "-g", "daemon off;"]
nginx / nginxsett
upstream apiprovider {
server apiprovider:8888;
}
server {
listen 7777;
listen 7778 ssl;
ssl on;
ssl_certificate /etc/nginx/service.crt;
ssl_certificate_key /etc/nginx/service.key;
location / {
proxy_pass http://apiprovider/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}