我有一个包含一个nginx和一个php-fpm服务的docker swarm。我的问题是,从群中的其他服务,我随机得到错误Failed to connect to nginx-fpm port 8081: Host unreachable
。
nginx和fpm图像来自官方的docker图像,配置更改很少。
nginx-fpm dockerfile
FROM nginx:1.13.12-alpine
COPY ./nginx/config/ /etc/nginx/
ADD ./nginx/docker/entrypoint.sh /bin/
EXPOSE 8081
ENTRYPOINT ["/bin/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
nginx config
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
accept_mutex on;
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 {
listen 8081;
server_name worker;
keepalive_timeout 30;
send_timeout 30s;
fastcgi_read_timeout 30s;
client_max_body_size 1024M;
root /app/www;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
}
}
我尝试启用nginx_status的事件,但我只能看到1个活动连接(或主机无法访问)。
在我看来,nginx只能处理一个连接,但我找不到原因......任何帮助都有所帮助
答案 0 :(得分:0)
您如何在Swarm中运行服务?
通常,您需要在外部公开服务端口,如下所示:
$ docker service create --name my_service \
--replicas 3 \
--publish published=8081,target=8081 \
nginx-fpm