【发布时间】:2020-12-06 10:33:55
【问题描述】:
我已经构建了一个集群(1 名经理,4 名工人)。只有 manager 有公网 IP,worker 和 manager 在私网。
我尝试使用 Docker Swarm 构建一个网络服务器(Nginx + PHP-FPM)。所以我在manager上设置了Nginx容器,这样就可以从私网外部请求了。如果我这样做,容器在请求 PHP 文件时会收到 upstream timed out (110: Connection timed out) while connecting to upstream 错误。如果我在工作节点上运行它,一切正常,但无法从专用网络外部访问 Nginx(我只能在管理器或每个工作人员上使用 curl 请求)。
你们有什么想法吗?我真的不明白为什么在管理器上运行 Nginx 会导致 PHP-FPM 超时。谢谢!
这里是docker-compose.yml 文件:
version: '3.8'
services:
nginx:
image: arm32v5/nginx:latest
container_name: webserver_nginx
ports:
- 80:80
volumes:
- /media/storage/webserver/nginx/nginx.conf:/etc/nginx/nginx.conf
- /media/storage/webserver/nginx/log:/var/log/nginx
- /media/storage/www:/var/www
links:
- php
networks:
- webserver
deploy:
placement:
constraints:
- "node.role==manager"
php:
image: arm32v5/php:7.4-fpm
container_name: webserver_php
volumes:
- /media/storage/www:/var/www
- /media/storage/webserver/nginx/www.conf:/usr/local/etc/php-fpm.d/www.conf
networks:
- webserver
links:
- nginx
ports:
- 9000:9000
networks:
webserver:
driver: overlay
attachable: true
Nginx 配置:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server_tokens off;
server {
listen 80;
error_page 500 502 503 504 /50x.html;
location / {
index index.php index.html index.htm;
root /var/www/;
}
location ~ \.php$ {
root /var/www/;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
}
【问题讨论】:
标签: php docker nginx docker-swarm