Learn about Centmin Mod LEMP Stack today
Register Now

Nginx PHP-FPM Nginx-FPM Performance Configs And Values

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

Tags:
  1. skringjer

    skringjer Member

    49
    6
    8
    Apr 21, 2019
    Ratings:
    +7
    Local Time:
    9:23 PM
    Please fill in any relevant information that applies to you:
    • CentOS Version: 7.6.1810
    • Centmin Mod Version Installed: 123.09beta01.b151
    • Nginx Version Installed: 1.15.12
    • PHP Version Installed: 7.3.4
    • MariaDB MySQL Version Installed: 10.3.14
    • When was last time updated Centmin Mod code base ? : On Automatic Cron Updates
    • Persistent Config:
      Code (Text):
      LETSENCRYPT_DETECT='y'
      VHOSTCTRL_CLOUDFLAREINC='y'
      

    Hi, so i have made some performance optimizations of Nginx in php-mycustom.conf and included this file in my Nginx Vhost, now these works and some valvues that i have set are
    Code:
    fastcgi_connect_timeout 3000s;
    fastcgi_send_timeout 3000s;
    fastcgi_read_timeout 3000s;
    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;
    send_timeout 3000s;
    proxy_connect_timeout 3000s;
    proxy_send_timeout  3000s;
    proxy_read_timeout  3000s;
    client_max_body_size 0;
    But today while i was doing some test i got Nginx 413 Entity too large error which is defintely linked to client_max_body_size and as you can see in the above conf file its set to 0 means disabled, still i got the error then i read some posts of other users on Centmin forum that this value is set in nginx.conf

    My question is that should php-mycustom.conf override nginx.conf values? and now i am confused whether the other above values are used from php-mycustom.conf or nginx.conf how can i know this? There was a command in the FAQ guides but that wasnt working and would give me authentication error. Thanks

    And when Centmin and nginx upgrades, will changes be lost which are made in

    domain.com.ssl.conf
    php-mycustom.conf
    php-fpm.conf
    nginx.conf
     
  2. eva2000

    eva2000 Administrator Staff Member

    39,758
    8,769
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,494
    Local Time:
    2:23 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Centmin Mod is provide as is, so short of scripted related bugs or issues, any further optimisation to the web stack components - nginx, php-fpm, mariadb mysql, csf firewall etc or web app specific configurations are left to the Centmin Mod user to deal with. So I do not provide any free support for such i.e. optimisations beyond default.

    However, Centmin Mod users are free to help each other out and ask questions or give answers on this community forum. My hopes are that this community forum evolves so that more veteran long time Centmin Mod users help new Centmin Mod users out :)

    FYI, do not set to 3000s for timeouts - what you're doing is letting rouge or runaway poor performing php scripts to hog all the php time which will crash php and end with 502 gateway timeout errors instead.

    you set client_max_body_size in /usr/local/nginx/conf/nginx.conf usually though server{} and location{} contexts are valid too

    Module ngx_http_core_module
    only one would be with php upgrades if you answer yes to prompt to overwrite php.conf custom changes (which also overwrites php-fpm.conf - need to change that wording in an update) - if you answer no to do not overwrite then php upgrade routine won't make any changes. While other files won't get automatic changes to custom settings you make

    if you set it in nginx.conf only it applies server wide so don't set it anywhere else

    i wouldn't set to 0 /disable - instead set it to large size/upper limit of your web app's allowed upload size as that would be the max size your web app would server via nginx
     
    Last edited: May 4, 2019
  3. skringjer

    skringjer Member

    49
    6
    8
    Apr 21, 2019
    Ratings:
    +7
    Local Time:
    9:23 PM
    The reason for setting such huge timeouts is because my web app uploads files in Chunks of 100 MBs and when all chunks are uploaded at the end they are compiled back into 1 file in Fileservers, so the main site / app has to wait for the compilation to complete, so a 200 GB file would take around 40 Minutes to compile and respond back to the main server, if i set a lower limit the uploads wont go through and give a 502 Bad Gateway timeout,

    This was one of the issue i couldn't diagnose in VestaCP even though i would setup huge timeouts still they would give 502 errors on 6.5 minutes where as i had set 50 minutes,

    As for the Client Max body, my API dosen't uploads files in chunks and hence i set it to zero to allow larger files, the API is being reworked so hopefully wont be needing to set that to 0 in the future.
     
  4. eva2000

    eva2000 Administrator Staff Member

    39,758
    8,769
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,494
    Local Time:
    2:23 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Workaround is to use a separate custom php.conf include file just for your upload script separate from rest of your php includes and ideally use a separate php-fpm pool from the main default php-fpm pool so that uploaded files use their own php-fpm pool + own custom php.conf include file with their own higher than default php-fpm timeouts and settings. This way uploads via custom php-fpm pool do not interfere with the rest of the site(s) php-fpm usage in the main default php-fpm pool.

    For multiple php-fpm pools there's already support for 4 additional php-fpm pools which you can manually configure to work in an upstream load balanced setup or as individual php-fpm pools. Details at https://community.centminmod.com/th...03-multiple-php-fpm-pools-support-added.3672/
     
  5. skringjer

    skringjer Member

    49
    6
    8
    Apr 21, 2019
    Ratings:
    +7
    Local Time:
    9:23 PM
    I am on it and will be setting up things in a more proper way now, 1 thing when i run centmin i get this error

    find: Invalid argument `+M' to -size

    before the centmin options comes up, anything to worry about?
     
  6. eva2000

    eva2000 Administrator Staff Member

    39,758
    8,769
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,494
    Local Time:
    2:23 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Run these command to run centmin.sh in debug mode and saved contents to /root/centminlogs/centmin-debug.txt. wait until you return to command prompt for completion of debug mode
    Code (Text):
    cmupdate
    cd /usr/local/src/centminmod
    echo 24 | bash -x centmin.sh 2>&1 | sed -e "s|$(hostname -f)|hostname|g" -e "s|$(hostname -s)|hostname|g" | tee /root/centminlogs/centmin-debug.txt
    

    then post the contents of /root/centminlogs/centmin-debug.txt to pastebin.com or gist.github.com and share the link here or private message me with the link
     
  7. eva2000

    eva2000 Administrator Staff Member

    39,758
    8,769
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,494
    Local Time:
    2:23 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    what's output for command below
    Code (Text):
    awk '/client_max_body_size/ {print $2}' /usr/local/nginx/conf/nginx.conf

    seems problem is centmin mod didn't get value of client_max_body_size correctly so value is empty so find command used
    Code (Text):
    -maxdepth 4 -size +M
    

    instead of
    Code (Text):
    -maxdepth 4 -size +XXXM
    

    where XXX is value of client_max_body_size in megabytes

    this routine/find check is only triggered if you enabled and set AUTOTUNE_CLIENTMAXBODY='y' in persistent config file /etc/centminmod/custom_config.inc which is disabled by default
     
  8. skringjer

    skringjer Member

    49
    6
    8
    Apr 21, 2019
    Ratings:
    +7
    Local Time:
    9:23 PM
    Output of awk '/client_max_body_size/ {print $2}' /usr/local/nginx/conf/nginx.conf
    Code:
    0;
    cat /etc/centminmod/custom_config.inc
    Code:
    LETSENCRYPT_DETECT='y'
    VHOSTCTRL_CLOUDFLAREINC='y'
    Should i be worried about this or simply ignore it?
     
  9. eva2000

    eva2000 Administrator Staff Member

    39,758
    8,769
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,494
    Local Time:
    2:23 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    ah you set to disable client_max_body_size limit so value came back as 0 - will have to add a check for that but if you disable that with 0, then you can disable AUTOTUNE_CLIENTMAXBODY='y' as it only would auto tune client_max_body_size if you are actively using the client_max_body_size to limit max nginx file body size served.
     
  10. skringjer

    skringjer Member

    49
    6
    8
    Apr 21, 2019
    Ratings:
    +7
    Local Time:
    9:23 PM
    But as you can see in the cat /etc/centminmod/custom_config.inc i havent enabled AUTOTUNE_CLIENTMAXBODY='y'
     
  11. eva2000

    eva2000 Administrator Staff Member

    39,758
    8,769
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,494
    Local Time:
    2:23 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    ah i actually changed AUTOTUNE_CLIENTMAXBODY='y' to defaults in centmin.sh a while back. I updated 123.09beta01 with a fix for this to account for the value of client_max_body_size set to 0. So run cmupdate command and subsequent centmin.sh menu runs should be fixed now
     
  12. skringjer

    skringjer Member

    49
    6
    8
    Apr 21, 2019
    Ratings:
    +7
    Local Time:
    9:23 PM
    Yes issue fixed, working now thanks alot :)
     
    • Like Like x 1
..