Want more timely Centmin Mod News Updates?
Become a Member

PHP-FPM 502 Bad Gateway Timeout HELP

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by skringjer, Apr 21, 2019.

Tags:
  1. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    11:31 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    One thing more i wanted to ask due to these errors


    Code:
    nginx: [emerg] "fastcgi_connect_timeout" directive is duplicate in /usr/local/nginx/conf/php-mycustom.conf:19
    
    nginx: [emerg] "fastcgi_send_timeout" directive is duplicate in /usr/local/nginx/conf/php-mycustom.conf:19
    I removed the directives like fastcgi_connect_timeout and some others from /usr/local/nginx/conf/php-mycustom.conf

    Why did i face this issue? Cuz in the original php.conf these directives were present. but nginx restarted fine, i want to have them in mycustom.conf too
     
  2. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:31 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Glad to hear :)
     
  3. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:31 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    did you comment out the old php.conf include file in nginx vhost ?

    post contents of /usr/local/nginx/conf/php-mycustom.conf
    Code (Text):
    cat /usr/local/nginx/conf/php-mycustom.conf
     
  4. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    11:31 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    Yes i commented that out

    Code:
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on;
            include fastcgi_params;
        
    
    # 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 60s;
    fastcgi_send_timeout 180s;
    fastcgi_read_timeout 300s;
    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 off;
    
    # 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  HTTP_PROXY         "";
    
    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;
    
                       }
     
  5. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    11:31 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    if i remove all of these

    fastcgi_connect_timeout 60s;
    fastcgi_send_timeout 180s;
    fastcgi_read_timeout 300s;
    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 off;

    Then mycustom.php works otherwise nginx dosent restart.
     
  6. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:31 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    duplicate errors are due to you including fastcgi_params file as centminmod php.conf and your custom copy already has all fastcgi_params and additional settings added natively in the file
    Code (Text):
    include fastcgi_params;
    

    so comment out this fastcgi_params include file and re-enable/uncomment all the settings you commented out
     
  7. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    11:31 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    Thank you very much eva, everything is perfect, optimized and secure, i am just running some final tests now.

    1 Thing, why is the the upload and download speed not going above 40 Mbs? though i have 1 Gbits uplink both on the server and on my PC.

    Is there some os tuning required?
     
  8. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:31 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    depends on speed of your web host provider's network/peering and geographic distance between you and your server too. 1Gbit uplink is just that a physical link - what your real speed is depends on your web host and it's upstream connectivity relative to your geographic location. There's also underlying disk I/O performance of your server as download/uploads will read/write to disk.
     
  9. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    4:31 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Oh as you were using PHP 7.3.4, your 502 might be related to a PHP 7.3.4+ bug which I backported a fix from yet to be released PHP 7.3.7. So you can try updating 123.09beta01 via cmupdate and then re-run centmin.sh menu option 5 to recompile current PHP 7.3.5 release - though PHP 7.3.6 is available too and officially announced in 2-3 days from now Beta Branch - backport PHP 7.3.7 due bug fix into PHP 7.3.4-7.3.6 in 123.09beta01