![Docker NGINX + PHP-FPM:错误 502 错误网关](https://linux22.com/image/760436/Docker%20NGINX%20%2B%20PHP-FPM%EF%BC%9A%E9%94%99%E8%AF%AF%20502%20%E9%94%99%E8%AF%AF%E7%BD%91%E5%85%B3.png)
nginx 站点配置:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com;
location / {
index index.php index.html;
}
location ~* \.php$ {
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
docker-compose.yml
version: "3"
services:
webserver:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./wwwcontent:/var/www
- ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf/conf.d:/etc/nginx/conf.d
- ./ssl:/etc/ssl/
links:
- phpfpm
phpfpm:
image: php:7.4-fpm
volumes:
- ./wwwcontent:/var/www
expose:
- 9000
以下是我收到的错误:
connect() failed (113: No route to host) while connecting to upstream, client: 172.68.133.9, server: example.com, request: "GET /?5 HTTP/1.1", upstream: "fastcgi://172.24.0.2:9000", host: example.com
答案1
问题是防火墙阻止了 Docker 容器之间的通信。
此命令可修复此问题:firewall-cmd --set-default-zone=trusted
或禁用防火墙