Discover Centmin Mod today
Register Now

PHP-FPM 502 bad gateway - no live upstreams while connecting to upstream

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Feb 4, 2016.

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,087
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:43 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Hi

    I just move to a new server and i am getting 502 bad gateway :(

    php.conf:
    Code:
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_next_upstream error timeout http_500 http_503;
        fastcgi_pass phpbackend;
        fastcgi_keep_conn on;
        #fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $request_filename;
        fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/usr/local/lib/php/:/tmp/;
    
    # might shave 200+ ms off PHP requests
    # which don't pass on a content length header
    # slightly faster page response time at the
    # expense of throughput / scalability
    #sendfile on;
    #tcp_nopush off;
    #keepalive_requests 0;
    
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 512 16k;
    fastcgi_busy_buffers_size 1m;
    fastcgi_temp_file_write_size 4m;
    fastcgi_max_temp_file_size 4m;
    fastcgi_intercept_errors on;
    
    # next 3 lines when uncommented / enabled
    # allow Nginx to handle uploads which then
    # passes back the completed upload to PHP
    #fastcgi_pass_request_body off;
    #client_body_in_file_only clean;
    #fastcgi_param  REQUEST_BODY_FILE  $request_body_file;
    
    #new .04+ map method
    fastcgi_param HTTPS $server_https;
    
    # comment out PATH_TRANSLATED line if /usr/local/lib/php.ini sets following:
    # cgi.fix_pathinfo=0
    # as of centminmod v1.2.3-eva2000.01 default is set to cgi.fix_pathinfo=1
    
    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
    
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REQUEST_SCHEME     $scheme;
    fastcgi_param  HTTPS              $https if_not_empty;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # Set php-fpm geoip variables
    fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
    fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
    fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
    fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
    fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
    fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
    fastcgi_param GEOIP_REGION $geoip_region;
    fastcgi_param GEOIP_CITY $geoip_city;
    fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
    fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
    fastcgi_param GEOIP_LATITUDE $geoip_latitude;
    fastcgi_param GEOIP_LONGITUDE $geoip_longitude;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
    
                       }
    phpfpm_pool2.conf and pool3 pool4 pool5 same settings:


    Code:
    [pool2]
    user = nginx
    group = nginx
    
    listen = 127.0.0.1:9002
    listen.allowed_clients = 127.0.0.1
    listen.backlog = 65535
    
    ;listen = /tmp/php5-fpm-pool2.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0666
    
    pm = dynamic
    pm.max_children = 90
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 20
    pm.min_spare_servers = 10
    pm.max_spare_servers = 88
    pm.max_requests = 5000
    
    ; PHP 5.3.9 setting
    ; The number of seconds after which an idle process will be killed.
    ; Note: Used only when pm is set to 'ondemand'
    ; Default Value: 10s
    pm.process_idle_timeout = 10s;
    
    rlimit_files = 65536
    rlimit_core = 0
    
    ; The timeout for serving a single request after which the worker process will
    ; be killed. This option should be used when the 'max_execution_time' ini option
    ; does not stop script execution for some reason. A value of '0' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_terminate_timeout = 0
    ; Default Value: 0
    ;request_slowlog_timeout = 0
    slowlog = /var/log/php-fpm/www-slow-pool2.log
    
    pm.status_path = /phpstatus-pool2
    ping.path = /phpping-pool2
    ping.response = pong
    
    ; Limits the extensions of the main script FPM will allow to parse. This can
    ; prevent configuration mistakes on the web server side. You should only limit
    ; FPM to .php extensions to prevent malicious users to use other extensions to
    ; exectute php code.
    ; Note: set an empty value to allow all extensions.
    ; Default Value: .php
    security.limit_extensions = .php .php3 .php4 .php5
    
    ; catch_workers_output = yes
    php_admin_value[error_log] = /var/log/php-fpm/www-php.error-pool2.log
    php_admin_value[disable_functions] = shell_exec
    
    domain.com.conf

    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    server {
                listen   80;
                server_name domain.com;
                return 301 $scheme://www.domain.com$request_uri;
           }
    
    server {
     
      server_name www.domain.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always; 
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      root /home/nginx/domains/domain.com/public;
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
       deny all;
      }
    
      location / {
    
    # block common exploits, sql injections etc
    include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      try_files    $uri $uri/ /index.php;
    
      }
    
    location ^~/admin/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswdad;
    include /usr/local/nginx/conf/php.conf;
    }
    
       location ~^(/uploads/).*(\.php)$ {
            deny     all;
        }
    
       location ~^(/uploads/gadgets/images/).*(\.php)$ {
            deny     all;
        }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    domains error.log:

    Code:
    [error] 68330#68330: *107 no live upstreams while connecting to upstream, client: 79.130.34.23, server: www.domain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://phpbackend",
    Code:
    # ss -nlt | grep 900
    LISTEN     0      57050  127.0.0.1:9000                     *:*
    LISTEN     0      57050  127.0.0.1:9002                     *:*
    LISTEN     0      57050  127.0.0.1:9003                     *:*
    LISTEN     0      57050  127.0.0.1:9004                     *:*
    LISTEN     0      57050  127.0.0.1:9005                     *:*
    
    tail -20 /usr/local/nginx/logs/error.log
    Code:
    2016/02/02 21:37:15 [emerg] 1774#1774: "root" directive is duplicate in /usr/local/nginx/conf/conf.d/domainb.com.conf:88
    2016/02/02 21:38:38 [warn] 2178#2178: conflicting server name "domainb.com" on 0.0.0.0:80, ignored
    2016/02/02 21:41:36 [warn] 3516#3516: conflicting server name "domainb.com" on 0.0.0.0:80, ignored
    2016/02/02 21:45:12 [emerg] 5158#5158: "root" directive is duplicate in /usr/local/nginx/conf/conf.d/domainb.com.conf:39
    2016/02/02 21:45:49 [emerg] 5222#5222: "location" directive is not allowed here in /usr/local/nginx/conf/conf.d/domainb.com.conf:44
    2016/02/02 21:46:51 [emerg] 5300#5300: zero size shared memory zone "alpha"
    2016/02/02 21:47:19 [emerg] 5349#5349: zero size shared memory zone "alpha"
    2016/02/02 21:47:28 [emerg] 5392#5392: zero size shared memory zone "alpha"
    2016/02/02 21:48:33 [emerg] 6358#6358: zero size shared memory zone "alpha"
    I am just redirecting the domainb.com to a path at domain.com....

    The old server domainb.com doesn't start at all on new server.... :( The above start but it doesn't work....

    Thanks
     
  2. pamamolf

    pamamolf Premium Member Premium Member

    4,087
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:43 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok i fix it by re importing my database.....Don't know why is this error is related to that but anyway :)

    Can you please help with this errors? If i can adjust something to avoid them?
    Code:
    2016/02/02 21:37:15 [emerg] 1774#1774: "root" directive is duplicate in /usr/local/nginx/conf/conf.d/domainb.com.conf:88
    2016/02/02 21:38:38 [warn] 2178#2178: conflicting server name "domainb.com" on 0.0.0.0:80, ignored
    2016/02/02 21:41:36 [warn] 3516#3516: conflicting server name "domainb.com" on 0.0.0.0:80, ignored
    2016/02/02 21:45:12 [emerg] 5158#5158: "root" directive is duplicate in /usr/local/nginx/conf/conf.d/domainb.com.conf:39
    2016/02/02 21:45:49 [emerg] 5222#5222: "location" directive is not allowed here in /usr/local/nginx/conf/conf.d/domainb.com.conf:44
    2016/02/02 21:46:51 [emerg] 5300#5300: zero size shared memory zone "alpha"
    2016/02/02 21:47:19 [emerg] 5349#5349: zero size shared memory zone "alpha"
    2016/02/02 21:47:28 [emerg] 5392#5392: zero size shared memory zone "alpha"
    2016/02/02 21:48:33 [emerg] 6358#6358: zero size shared memory zone "alpha"
     
  3. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    10:43 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    post contents of /usr/local/nginx/conf/conf.d/domainb.com.conf in CODE tags
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    4,087
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:43 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Code:
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    server {
                listen   80;
                server_name domainb.com;
                return 301 $scheme://www.domainb.com$request_uri;
           }
    
    server {
     
      server_name www.domainb.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always; 
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      root /home/nginx/domains/domain.com/public;
      index index.php;
    
      access_log /home/nginx/domains/domainb.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/domainb.com/log/error.log;
    
    location /go/ {
      return 301 http://www.domainb.com/;
    }
    
      location /blog/ {
        deny all;
    }
    
    error_page 500 502 504 /500.html;
    
      location ~* ^.+\.(?:css|cur|js|jpg|jpeg|gif|ico|png|html|xml|zip|rar|mp4|3gp|flv|webm|f4v|ogm)$ {
        access_log off;
        expires 30d;
        tcp_nodelay off;
        open_file_cache max=3000 inactive=120s;
        open_file_cache_valid 45s;
        open_file_cache_min_uses 2;
        open_file_cache_errors off;
    
    }
    
      location /api2/ {
        rewrite ^/api2/(.*)$ /api/public/index.php?route=$1 last;
      }
    
      location ~* /(uploads|public)/ {
         access_log off;
         expires 30d;
      }
    
    
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
       deny all;
      }
    
      location / {
    
    # block common exploits, sql injections etc
    include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      try_files    $uri $uri/ /index.php;
    
      }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
     
  5. eva2000

    eva2000 Administrator Staff Member

    54,909
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    10:43 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    you sure that is the same vhost as the error reported line numbers don't line up with the posted vhost
    Code:
    2016/02/02 21:37:15 [emerg] 1774#1774: "root" directive is duplicate in /usr/local/nginx/conf/conf.d/domainb.com.conf:88
    2016/02/02 21:38:38 [warn] 2178#2178: conflicting server name "domainb.com" on 0.0.0.0:80, ignored
    2016/02/02 21:41:36 [warn] 3516#3516: conflicting server name "domainb.com" on 0.0.0.0:80, ignored
    2016/02/02 21:45:12 [emerg] 5158#5158: "root" directive is duplicate in /usr/local/nginx/conf/conf.d/domainb.com.conf:39
    2016/02/02 21:45:49 [emerg] 5222#5222: "location" directive is not allowed here in /usr/local/nginx/conf/conf.d/domainb.com.conf:44
     
  6. pamamolf

    pamamolf Premium Member Premium Member

    4,087
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:43 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    damn ignore it.... i mess it with a few tests and maybe the errors are from another content.....