先贴一下 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 天了,国内外全部找遍了,没有找到解决方法
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/660618
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.