如何解决连接到Nginx代理上托管的网站时如何修复“ 502 Bad Gateway”
我正在尝试使用WordPress在Ubuntu VPS的docker容器内运行Nginx-Proxy应用。
我创建了以下docker-compose.yml
文件
version: '3.4'
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- 80:80
- 443:443
restart: always
networks:
- external
volumes:
- wordpress:/var/www/html
wordpress_app:
image: wordpress
restart: always
environment:
- VIRTUAL_HOST=sub.domain.com
- VIRTUAL_PORT=5500
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=db_username
- WORDPRESS_DB_PASSWORD=db_password
- WORDPRESS_DB_NAME=db_name
depends_on:
- nginx-proxy
- db
networks:
- internal
- external
volumes:
- wordpress:/var/www/html
ports:
- 5500:5500
db:
image: mysql:latest
restart: always
hostname: mysql
environment:
- VIRTUAL_PORT=3306
- MYSQL_DATABASE=db_name
- MYSQL_USER=db_username
- MYSQL_PASSWORD=db_password
- MYSQL_ROOT_PASSWORD=root_password
networks:
- internal
volumes:
- db:/var/lib/mysql
ports:
- 3306:3306
volumes:
wordpress:
db:
networks:
internal:
external:
现在,执行docker-compose up
会显示以下内容
Attaching to root_db_1,root_nginx-proxy_1,root_wordpress_app_1
db_1 | 2020-10-12 16:34:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
db_1 | 2020-10-12 16:34:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2020-10-12 16:34:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
db_1 | 2020-10-12T16:34:19.127860Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
db_1 | 2020-10-12T16:34:19.146953Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db_1 | 2020-10-12T16:34:20.318195Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
nginx-proxy_1 | WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
nginx-proxy_1 | is being generated in the background. Once the new dhparam.pem is in place,nginx will be reloaded.
nginx-proxy_1 | forego | starting dockergen.1 on port 5000
nginx-proxy_1 | forego | starting nginx.1 on port 5100
nginx-proxy_1 | dockergen.1 | 2020/10/12 16:34:18 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
nginx-proxy_1 | dockergen.1 | 2020/10/12 16:34:18 Watching docker events
nginx-proxy_1 | dockergen.1 | 2020/10/12 16:34:20 Generated '/etc/nginx/conf.d/default.conf' from 3 containers
nginx-proxy_1 | dockergen.1 | 2020/10/12 16:34:20 Received event start for container a6b94da9d7a7
nginx-proxy_1 | dockergen.1 | 2020/10/12 16:34:20 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
db_1 | 2020-10-12T16:34:20.960375Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060,socket: /var/run/mysqld/mysqlx.sock
db_1 | 2020-10-12T16:34:21.394031Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2020-10-12T16:34:21.394509Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
db_1 | 2020-10-12T16:34:21.425181Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-10-12T16:34:21.566194Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
wordpress_app_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name,using 172.25.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_app_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name,using 172.25.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_app_1 | [Mon Oct 12 16:34:22.661957 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.11 configured -- resuming normal operations
wordpress_app_1 | [Mon Oct 12 16:34:22.662180 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
nginx-proxy_1 | 2020/10/12 16:34:23 [notice] 49#49: signal process started
nginx-proxy_1 | Generating DH parameters,2048 bit long safe prime,generator 2
nginx-proxy_1 | This is going to take a long time
nginx-proxy_1 | dhparam generation complete,reloading nginx
然后,当我向http://sub.domain.com
请求时,在浏览器中出现以下错误
502错误的网关nginx / 1.17.6
我还在服务器上获得了以下日志。
nginx-proxy_1 | nginx.1 | 2020/10/12 16:35:07 [error] 51#51: *1 connect() failed (111: Connection refused) while connecting to upstream,client: MY_PERSOANL_IP_ADDRESS,server: sub.domain.com,request: "GET / HTTP/1.1",upstream: "http://172.25.0.3:5500/",host: "sub.domain.com"
nginx-proxy_1 | nginx.1 | sub.domain.com MY_PERSOANL_IP_ADDRESS - - [12/Oct/2020:16:35:07 +0000] "GET / HTTP/1.1" 502 157 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
nginx-proxy_1 | nginx.1 | sub.domain.com MY_PERSOANL_IP_ADDRESS - - [12/Oct/2020:16:35:08 +0000] "GET /favicon.ico HTTP/1.1" 502 157 "http://sub.domain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0"
nginx-proxy_1 | nginx.1 | 2020/10/12 16:35:08 [error] 51#51: *1 no live upstreams while connecting to upstream,request: "GET /favicon.ico HTTP/1.1",upstream: "http://sub.domain.com/favicon.ico",host: "sub.domain.com",referrer: "http://sub.domain.com/"
潜在问题
日志状态
2020/10/12 16:34:20从3个容器中生成了'/etc/nginx/conf.d/default.conf'
但是,当docker容器运行时,我执行cd /etc/nginx/conf.d
但得到-bash: cd: /etc/nginx/conf.d/: No such file or directory
。文件/etc/nginx/conf.d/default.conf
是否应该存在?
什么可能导致此问题?我该如何解决?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。