Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker fpm fallback 502 bad gateway #32

Open
fannyfan414 opened this issue Jul 4, 2019 · 1 comment
Open

docker fpm fallback 502 bad gateway #32

fannyfan414 opened this issue Jul 4, 2019 · 1 comment

Comments

@fannyfan414
Copy link

fannyfan414 commented Jul 4, 2019

My docker-compose

#Docker Networks
networks:
  app-network:
    driver: bridge
services:
  app:
    build: php-fpm
    container_name: app
    restart: always
    ports:
      - "9501:9501"
    #      - "9000:9000"
    #      - "81:81"
    expose:
      - 80
      - 9501
      - 9000
    #    entrypoint: "php vendor/scil/laravel-fly/bin/fly start"
    entrypoint: "php-fpm"
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    volumes:
      - ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
      - ./php-fpm/config:/usr/local/etc/php
    working_dir: ${APP_PATH_CONTAINER}
    networks:
      - app-network

  #Nginx Service
  nginx:
    build: nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"
    networks:
      - app-network
    working_dir: /app
    volumes:
      - ${APP_PATH_HOST}/public:/usr/share/nginx/html
      - ./nginx/conf.d/app.conf:/etc/nginx/nginx.conf
    command: [nginx-debug, '-g', 'daemon off;']

  db:
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    volumes:
      - ${DB_PATH_HOST}:/var/lib/mysql
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - "3306:3306"
    networks:
      - app-network

  adminer:
    image: adminer
    restart: always
    ports:
      - "6080:8080"
    networks:
      - app-network

My nginx app.conf

 user              www-data  www-data;
 worker_processes  5;
 
 pid        /var/run/nginx.pid;
 
 worker_rlimit_nofile 1024;
 
 # include /etc/nginx/modules-enabled/*.conf;
 
 events {
         worker_connections 512;
 }
 
 http {
 
         include /etc/nginx/mime.types;
         default_type application/octet-stream;
         sendfile off;
         tcp_nopush on;
         access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log warn;
 
 
 
 
         upstream default {
             server app:9501  weight=1 max_fails=1 fail_timeout=10 ;
             server app:81  backup;
 
             # The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.
             # It does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.
             # https://gist.github.com/magnetikonline/4a2e68b2ce94bd0c945e
             # https://ma.ttias.be/enable-keepalive-connections-in-nginx-upstream-proxy-configurations/
             keepalive 8;
         }
         upstream swoole {
             server app:9501;
         }
         upstream fpm {
             server app:81;
         }
 
         # map to different upstream backends based on query parameter 'useserver'
         # visit http://fly.test/?useserver=swoole to use server swoole
         # visit http://fly.test to use upstream default
         map $arg_useserver $pool {
              default "default";
              swoole "swoole";
              fpm "fpm";
         }
 
         log_format my_upstream '$remote_addr|$time_local|$request_time|$upstream_response_time|$status '
                                  '$upstream_addr|$request';
 
         server {
           server_name fly.test;
            listen 80;
            root /usr/share/nginx/html;
            index index.html;
           charset utf-8;
 
             location = / {
                 # if you have a static home page , try this one:
                 # try_files index.html @other;
                 try_files '' @php;
             }
 
             location / {
                 try_files $uri $uri/ @php;
             }
 
            location @php {
                 proxy_pass http://$pool;
 
                 # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
                 proxy_http_version 1.1;
                 # Remove the Connection header if the client sends it,
                 # it could be "close" to close a keepalive connection
                 proxy_set_header Connection "";
 
                 # proxy_connect_timeout 60s;
                 # proxy_send_timeout 60s;
                 # proxy_read_timeout 120s;
 
                 proxy_set_header    X-Real-IP        $remote_addr;
                 proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
                 proxy_set_header    Host             $http_host;
 
                 # proxy_set_header X-Real-PORT $remote_port;
                 # proxy_set_header Scheme $scheme;
                 # proxy_set_header Server-Protocol $server_protocol;
                 # proxy_set_header Server-Name $server_name;
                 # proxy_set_header Server-Addr $server_addr;
                 # proxy_set_header Server-Port $server_port;
 
                 # just a mark for different upstream server, you can disable it
                 add_header X-Upstream $upstream_addr;
                 # log
                 access_log /var/log/nginx/upstream.log my_upstream;
 
            }
 
         #    # only for Let's Encrypt
         #    location ~ /.well-known {
         #        allow all;
         #        # set root is necessage, otherwise "Invalid response from domain..."
         #        # https://www.digitalocean.com/community/questions/letsencrypt-problem-renewing-certs-invalid-response-from-domain
         #        root  {{ doc_root }};
         #    }
 
         }
 
 
         server {
            server_name fly.test;
            listen 81;
            root /usr/share/nginx/html;
            index index.html index.php;
            charset utf-8;
 
            location / {
                 try_files '' /index.php?$query_string;
             }
 
             location /index.php {
                fastcgi_pass app:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
            }
 
       }
     }

Swoole works well, but php-fpm always get 502 bad gateway

@fannyfan414
Copy link
Author

change code to this and everything start work

upstream default {
            server app:9501  weight=1 max_fails=1 fail_timeout=10 ;
            server 127.0.0.1:81  backup;

            # The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.
            # It does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.
            # https://gist.github.com/magnetikonline/4a2e68b2ce94bd0c945e
            # https://ma.ttias.be/enable-keepalive-connections-in-nginx-upstream-proxy-configurations/
            keepalive 8;
        }
        upstream swoole {
            server app:9501;
        }
        upstream fpm {
            server 127.0.0.1:81;
        }

But now if i make any request to server, than i always get error

LaravelFly\Map\IlluminateBase\SingletonRequestException: in file /var/www/html/vendor/scil/laravel-fly-files/src/Request.php on line 460
Stack trace:

  1. LaravelFly\Map\IlluminateBase\SingletonRequestException->() /var/www/html/vendor/scil/laravel-fly-files/src/Request.php:460
  2. Illuminate\Http\Request->createFrom() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php:34
  3. Illuminate\Foundation\Providers\FormRequestServiceProvider->Illuminate\Foundation\Providers{closure}() /var/www/html/vendor/scil/laravel-fly-files/src/Container.php:1008
  4. Illuminate\Container\Container->fireCallbackArray() /var/www/html/vendor/scil/laravel-fly-files/src/Container.php:953
  5. Illuminate\Container\Container->fireResolvingCallbacks() /var/www/html/vendor/scil/laravel-fly-files/src/Container.php:608
  6. Illuminate\Container\Container->resolve() /var/www/html/vendor/scil/laravel-fly-files/src/Container.php:540
  7. Illuminate\Container\Container->make() /var/www/html/vendor/scil/laravel-fly-files/src/Application.php:740
  8. Illuminate\Foundation\Application->make() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/RouteDependencyResolverTrait.php:238
  9. Illuminate\Routing\ControllerDispatcher->transformDependencyH() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/RouteDependencyResolverTrait.php:144
  10. Illuminate\Routing\ControllerDispatcher->resolveMethodDependenciesH() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/RouteDependencyResolverTrait.php:99
  11. Illuminate\Routing\ControllerDispatcher->resolveClassMethodDependencies() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:41
  12. Illuminate\Routing\ControllerDispatcher->dispatch() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:219
  13. Illuminate\Routing\Route->runController() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:176
  14. Illuminate\Routing\Route->run() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/Router.php:539
  15. Illuminate\Routing\Router->Illuminate\Routing{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
  16. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
  17. Illuminate\Routing\Middleware\SubstituteBindings->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  18. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  19. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php:58
  20. Illuminate\Routing\Middleware\ThrottleRequests->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  21. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
  22. Illuminate\Routing\Pipeline->Illuminate\Routing{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
  23. Illuminate\Pipeline\Pipeline->then() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/Router.php:541
  24. Illuminate\Routing\Router->runRouteWithinStack() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/Router.php:523
  25. Illuminate\Routing\Router->runRoute() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/Router.php:492
  26. Illuminate\Routing\Router->dispatchToRoute() /var/www/html/vendor/scil/laravel-fly-files/src/Routing/Router.php:487
  27. Illuminate\Routing\Router->dispatch() /var/www/html/vendor/scil/laravel-fly/src/LaravelFly/Map/CommonHack/Kernel.php:13
  28. LaravelFly\Map\Kernel->LaravelFly\Map\CommonHack{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:128
  29. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/fideloper/proxy/src/TrustProxies.php:57
  30. Fideloper\Proxy\TrustProxies->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  31. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
  32. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  33. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
  34. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  35. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
  36. Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  37. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
  38. Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:163
  39. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
  40. Illuminate\Pipeline\Pipeline->then() /var/www/html/vendor/scil/laravel-fly/src/fly/Kernel.php:135
  41. LaravelFly\Map\Kernel->sendRequestThroughRouter() /var/www/html/vendor/scil/laravel-fly/src/fly/Kernel.php:99
  42. LaravelFly\Map\Kernel->handle() /var/www/html/vendor/scil/laravel-fly/src/LaravelFly/Server/HttpServer.php:98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant