yeszao / dnmp

Docker LNMP (Nginx, PHP7/PHP5, MySQL, Redis)
https://www.awaimai.com/2120.html
MIT License
3.96k stars 1.41k forks source link

这样 nginx 访问 不到swoole2 #146

Closed ming200825 closed 5 years ago

ming200825 commented 5 years ago

[error] 12#12: *3 no resolver defined to resolve swoole2, proxy_pass http://172.21.0.6:9501$suffix; 这样可以用 proxy_pass http://swoole:9501$suffix; 这样用不了

看 你php 是这样配置的 不知道哪出错了

services:
  nginx:
    image: nginx:${NGINX_VERSION}
    ports:
      - "${NGINX_HTTP_HOST_PORT}:80"
      - "${NGINX_HTTPS_HOST_PORT}:443"
    volumes:
      - ${SOURCE_DIR}:/var/www/html/:rw
      - ${NGINX_CONFD_DIR}:/etc/nginx/conf.d/:rw
      - ${NGINX_CONF_FILE}:/etc/nginx/nginx.conf:ro
      - ${NGINX_LOG_DIR}:/var/log/nginx/:rw
    restart: always
    networks:
      - default

  php72:
    build:
      context: .
      args:
        PHP_VERSION: ${PHP72_VERSION}
        ALPINE_REPOSITORIES: ${ALPINE_REPOSITORIES}
        PHP_EXTENSIONS: ${PHP72_EXTENSIONS}
        MORE_EXTENSION_INSTALLER: php72.sh
    volumes:
      - ${SOURCE_DIR}:/var/www/html/:rw
      - ${PHP72_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro
      - ${PHP72_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw
      - ${PHP72_LOG_DIR}:/var/log/php
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      - default

  swoole:
    image: dnmp_php72
    volumes:
      - ${SOURCE_DIR}:/var/www/html/:rw
      - ${PHP72_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro
      - ${PHP72_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw
      - ${PHP72_LOG_DIR}:/var/log/php
    restart: always
    expose:
      - "9501"
    cap_add:
      - SYS_PTRACE
    command: php /var/www/html/permisionapi/swoole_server.php
    networks:
      - default
ming200825 commented 5 years ago

问题 解决了 是这里的问题 我的swoole 是http 服务 不是像php-fpm 那样的sock 所有要 用 upstream swoole { server swoole:9501; } 在用这个 转发 proxy_pass http://swoole$suffix;

zht1026 commented 5 years ago

你好 我也在配置 swoole 扩展 我安装了swoole扩展 ,问下具体的步骤,怎么配置PHP才能连接上swoole呢?

askme-gpt commented 3 years ago

只需要做两步,第一,在yml里面配置暴露的端口号; 第二步,写好nginx配置文件即可.

yml配置:


  php:
    build:
      context: ./services/php
      args:
        PHP_VERSION: php:${PHP_VERSION}-fpm-alpine
        CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL}
        PHP_EXTENSIONS: ${PHP_EXTENSIONS}
        TZ: "$TZ"
    container_name: php
    ports:
      - "9501:9501"
      - "9502:9502"
      - "9503:9503"
      - "9504:9504"
      - "9505:9505"
      - "9506:9506"
    extra_hosts:
      - "www.site1.com:172.17.0.1"
    volumes:
      - ${SOURCE_DIR}:/www/:rw
      - ${PHP_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro
      - ${PHP_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw
      - ${PHP_LOG_DIR}:/var/log/php
      - ${DATA_DIR}/composer:/tmp/composer
    restart: always
    cap_add:
      - SYS_PTRACE
    networks:
      - default

nginx配置

server {
    listen       9502;
    server_name  xxxx.test *.xxxx.test;
    root   /www/xxxx;
    index  index.php index.html index.htm;
    #charset koi8-r;

    access_log /dev/null;
    #access_log  /var/log/nginx/nginx.xxxx.access.log  main;
    error_log  /var/log/nginx/nginx.xxxx.error.log  warn;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

server {
    listen 443 ssl http2;
    server_name xxxx.test *.xxxx.test;
    root   /www/xxxx;
    index  index.php index.html index.htm;
    #charset koi8-r;

    access_log /dev/null;
    #access_log  /var/log/nginx/nginx.xxxx.access.log  main;
    error_log  /var/log/nginx/nginx.xxxx.error.log  warn;

    #error_page  404              /404.html;

    ssl_certificate /ssl/localhost/localhost.crt;
    ssl_certificate_key /ssl/localhost/localhost.key;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}