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
    
    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)