dongzhuoxie1244 2018-06-05 20:02
浏览 196

Nginx和php-fpm - 主机无法访问

I have docker swarm containing one nginx and one php-fpm service. My problem is, that from other services in swarm, I randomly get error Failed to connect to nginx-fpm port 8081: Host unreachable.

nginx and fpm images are from official docker images with little config changes.

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;
        }
    }
}

I tried event enabling nginx_status, but I can only see 1 active connection (or host unreachable).

It looks like to me, that nginx is only able to handle one connection at time, but I cannot find reason why... any help appreciated

  • 写回答

1条回答 默认 最新

  • dongyu3712 2018-06-05 20:27
    关注

    How are you running your service in Swarm?

    Generally, you need to expose the service port externally, something like this:

    $ docker service create --name my_service \
                            --replicas 3 \
                            --publish published=8081,target=8081 \
                            nginx-fpm
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题