几度崩溃, docker 下配置的 nginx 无论如何也连不上 gunicorn, 希望有经验的朋友指点以下,刚接触 docker
- 0次
- 2021-06-17 14:13:52
- idczone
先贴一下 nginx 错误日志
nginx error.log 的错误日志
2020/04/08 15:00:15 [error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.223.16.212, server: www.cakevin.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.60.58.127"
2020/04/08 15:03:20 [error] 6#6: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 99.254.94.66, server: www.cakevin.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "cakevin.com"
2020/04/08 15:03:21 [error] 6#6: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 99.254.94.66, server: www.cakevin.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "cakevin.com", referrer: "http://cakevin.com/"
目前用 IP:8000 端口可以访问,登录,就是没有样式,静态文件没有被找到,
用 cakevin.com:80 访问报 502
用 ip:80 无法访问此网站 拒绝了我们的连接请求。
Django setting 测试设置的 ALLOWED_HOSTS = ['*'] 应该不是这个问题
容器信息
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ccc02234bc5 cakevin_nginx "nginx -g 'daemon of…" 10 seconds ago Up 7 seconds 0.0.0.0:80->80/tcp cakevin_nginx_1
22b222635f17 cakevin:1.1 "bash start.sh" 12 seconds ago Up 10 seconds 0.0.0.0:8000->8000/tcp cakevin_cakevin_1
d95336fabb61 mysql:5 "docker-entrypoint.s…" 13 seconds ago Up 11 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp cakevin_db_1
我的 docker-compose.yml 配置如下:
version: "3"
services:
db:
image: mysql:5
environment:
- MYSQL_HOST=localhost
- MYSQL_DATABASE=cakevin
- MYSQL_ROOT_PASSWORD=111111
ports:
- 3306:3306
restart: always
cakevin:
image: cakevin:1.1
ports:
- "8000:8000"
volumes:
- /home/cakevin:/cakevin
links:
- db
depends_on:
- db
command: bash start.sh
restart: always
nginx:
build:
context: .
dockerfile: dockerfile_nginx
ports:
- "80:80"
volumes:
- /home/cakevin/static:/usr/share/nginx/html/static
- /home/nginx/logs:/var/log/nginx
- /home/nginx/conf.d:/etc/nginx/conf.d
links:
- cakevin
depends_on:
- cakevin
restart: always
dockerfile_nginx 的配置如下
FROM nginx
EXPOSE 80
RUN apt-get upgrade && apt-get update && apt-get -y install vim
RUN mkdir -p /usr/share/nginx/html/static
nginx 的 conf.d 里的配置文件是
server {
listen 80;
server_name cakevin.com;
location /static {
alias /usr/share/nginx/html/static;
}
location / {
proxy_set_header Host $host;
proxy_pass http://0.0.0.0:8000;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
请大家帮忙给看一下,刚接触 docker,有点晕,已经搜索了 1 天了,国内外全部找遍了,没有找到解决方法
proxy_pass 是 localhost 是不是不对? 不应该是 cakevin 什么吗?
感谢,我把
proxy_pass http://0.0.0.0:8000;
改为
proxy_pass http://cakevin:8000;
就搞定 le ,感谢,感谢!!!!!!!
为了防止你连不上数据库,你连数据库的时候不要写 localhost:3306 了,应该是 db:3306
到底是一样的
你可以理解为 docker 给这些 service 分配了“域名”,他们就是你写在 services 下的每个 service 的名字
“道理是一样”,写错字,typo,sorry
设置这些应用都使用同一个 network 肯定没问题
为啥写 0.0.0.0
太谢谢谢了,真的是感谢,我发现这个平台的人真好。祝一生幸福
感谢感谢,已经解决
已经改了,感谢
1