Welcome to Centmin Mod Community
Become a Member

Nginx Nginx timeout on pages with many images

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by jair, Apr 6, 2017.

  1. jair

    jair New Member

    19
    1
    3
    Jan 8, 2017
    Ratings:
    +2
    Local Time:
    11:21 AM
    • CentOS Version: CentOS 7 64bit ?
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: 1.11.12
    • PHP Version Installed: 7.1.x
    • MariaDB MySQL Version Installed: 10.1.21
    • When was last time updated Centmin Mod code base ? : about a week ago
    I am having some issues on my forum. Some topics are very image heavy and apparently on slower connections they tend to time out. What happens is that if you open the topic with very fast connection everything loads quickly, but if your connection is slow, after some time all unloaded images are listed as broken. Apparently, the slower your connection is, the more images fail to load.

    Any idea which parameter I can tweak and will it have any detrimental effects on the overall load and speed of the server? I am surprised, because on apache I didn't had such issues and nginx is supposed to be excellent at handing many static files.
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,921
    6,909
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,405
    Local Time:
    7:21 PM
    Nginx 1.13.x
    MariaDB 5.5
    nginx 1.11.13 was just released with many bug fixes https://community.centminmod.com/threads/nginx-1-11-13-released.11129/

    what forum software ? also got an example url/thread ?

    nginx and php-fpm installed by Centmin Mod have more reasonable timeout values so if you images are really huge they don't hog your php-fpm processes so that could explain timeouts if nothing else is wrong

    test your forum thread url in gtmetrix.com and webpagetest.org which allow you to change ISP connection speed to simulate slower connections
     
    • Like Like x 1
  3. jair

    jair New Member

    19
    1
    3
    Jan 8, 2017
    Ratings:
    +2
    Local Time:
    11:21 AM
    Thanks, another guy is optimizing my server, but I am also trying to understand what is going on, because I intend to manage it myself. There is a possibility he changed the timeouts to more conservative levels. I am using IPS. Here is a sample url with many pictures: Записки от Екватора- част 7: В рая на света - Бали /2/

    Trying webpagetest now, with my manual counting, the timeout kicks in around 70 sec. Here is the webpagetest result, I believe again around 75 sec the connection is interrupted and the remaining images don't load: https://www.webpagetest.org/result/170406_E0_FQC/1/details/#waterfall_view_step1 Even though, no error code is transmitted.
     
  4. pamamolf

    pamamolf Well-Known Member

    2,819
    251
    83
    May 31, 2014
    Ratings:
    +445
    Local Time:
    11:21 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    70 sec for opening a single page?

    You can use Cloudflare to help you with so many high quality images.

    Doesn't sound like a server/Centminmod issue....
     
  5. eva2000

    eva2000 Administrator Staff Member

    30,921
    6,909
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,405
    Local Time:
    7:21 PM
    Nginx 1.13.x
    MariaDB 5.5
    there's your problem page size is too large at 2,794KB for 2G connection taking 92+ seconds on slow mobile

    Mobile 2G profile is 280Kbits/s with 800ms latency on webpagetest.org. That means 280/10= 28KB/s so 1MB = 1024KB/28 = 36.57 seconds per MB download speed!

    upload_2017-4-6_18-55-19.png

    aim for <700-1000KB page size for best speeds.
     
    Last edited: Apr 6, 2017
  6. eva2000

    eva2000 Administrator Staff Member

    30,921
    6,909
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,405
    Local Time:
    7:21 PM
    Nginx 1.13.x
    MariaDB 5.5
    most sites will still be slow over 2G though, even this forum takes longer to load on 2G mobile speeds

    wpt-cmmforum-index-2g-mobile-01.png
     
  7. jair

    jair New Member

    19
    1
    3
    Jan 8, 2017
    Ratings:
    +2
    Local Time:
    11:21 AM
    Yes, I am aware what is the issue and I don't imply it is a problem with centminmod :) My question was why there were no such problems with apache, with it, I believe you can wait 4-5 minutes for the entire page to load and it won't timeout like this. Even though nginx is supposed to be better at static content.

    And yeah, I am considering cloudflare.
     
  8. eva2000

    eva2000 Administrator Staff Member

    30,921
    6,909
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,405
    Local Time:
    7:21 PM
    Nginx 1.13.x
    MariaDB 5.5
    That's down to more sensible timeouts set in Centmin Mod Nginx + PHP-FPM otherwise site will slow down and increase cpu and server resource usage. Also Nginx can serve static files but if you use forum software it can go through PHP/PHP-FPM which doesn't like long running processes and can timeout. So if PHP-FPM had to wait 4-5 minutes, you'd consume all PHP-FPM children and workers and crash PHP-FPM.

    For custom php settings read centminmod.com/phpfpm.html#customphpini. You might want to create /etc/centminmod/php.d/b_customphp.ini to override centmin mod defaults at /etc/centminmod/php.d/a_customphp.ini and restart PHP-FPM.

    Also outlined in Getting Started Guide Step 17

    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.

    Bad gateway 502 /504 timeouts are usually related to Nginx timing out waiting on PHP-FPM to respond as PHP-FPM is overloaded or overwhelmed with requests, so may need to tune PHP-FPM values. It also maybe due to PHP-FPM in turn being queued and backed up waiting on MariaDB MySQL server to respond - so also need to look at MySQL.

    You'll need to tune your PHP-FPM settings with php-fpm main pool config file at /usr/local/etc/php-fpm.conf (overview of config files) and this is left up to end user to do but here's a thread for starters to enable php status page output outlined at

    Checking PHP-FPM etc logs



    You'll also need to check into your PHP-FPM, Nginx and MariaDB logs which you can find as outlined at How to troubleshoot Centmin Mod initial install issues

    Server logs include Nginx, PHP-FPM, MariaDB MySQL error logs as well as others. You can find your Centmin Mod install/menu logs at FAQ 7 and server logs at FAQ 19 at Centmin Mod FAQ (most up to date info in FAQ so always read that first). Spoiler tag below has info too but may not be up to date.

    Some of Centmin Mod's installed software will have their own access and error logs which maybe useful for diagnosing errors or give info, notes, or warning notices.

    Note: There's no support provided by me for diagnosing such errors which may occur for various reasons including misconfiguration of installed php/mysql scripts or applications.

    In SSH2 telnet you can use tail command to view the last X number of lines in the file.

    For example for viewing last 10 lines in the file for:

    For Nginx access and error logs:
    Code:
      tail -10 /usr/local/nginx/logs/access.log
      tail -10 /usr/local/nginx/logs/error.log
    
    For specific domainname.com access and error log:
    Code:
      tail -10 /home/nginx/domains/domainname.com/log/access.log
      tail -10 /home/nginx/domains/domainname.com/log/error.log
    
    For other system error logs located at /var/log:

    list /var/log files in ascending time order so the most recently modified files are at the bottom
    Code:
      ls -lhrt /var/log
    
    Code:
    total 2.7M
    -rw------- 1 root  root    0 Aug 29 15:33 tallylog
    -rw------- 1 root  root    0 Aug 29 15:33 spooler
    drwx------ 3 root  root 4.0K Aug 29 15:35 samba
    drwxr-xr-x 2 root  root 4.0K Aug 29 15:35 mail
    -rw-r--r-- 1 root  500     0 Oct  8 18:13 dmesg.old
    -rw------- 1 root  500     0 Oct  8 18:13 boot.log
    -rw-r--r-- 1 root  500     0 Oct  8 18:14 dmesg
    drwx------ 2 root  root 4.0K Oct  8 18:14 httpd
    drwxr-xr-x 2 root  root 4.0K Oct  8 19:08 php-fpm
    -rw-rw---- 1 mysql root 2.3K Oct  9 12:38 mysqld.log
    -rw------- 1 root  root 9.2K Oct 26 10:48 yum.log
    -rw------- 1 root  utmp  94K Nov  7 22:59 btmp
    drwxr-xr-x 2 root  root 4.0K Nov  8 00:00 sa
    -rw------- 1 root  root 269K Nov  8 21:39 messages
    -rw------- 1 root  root 110K Nov  8 23:08 secure
    -rw-rw-r-- 1 root  utmp  43K Nov  8 23:08 wtmp
    -rw-r--r-- 1 root  root 144K Nov  8 23:08 lastlog
    -rw------- 1 root  root  69K Nov  8 23:08 lfd.log
    -rw------- 1 root  root 332K Nov  8 23:08 maillog
    -rw------- 1 root  500  1.6M Nov  8 23:10 cron
    
    For PHP-FPM error log:
    Code:
      tail -10 /var/log/php-fpm/www-error.log
    
    and/or
    Code:
      /var/log/php-fpm/www-php.error.log
    
    For MySQL / MariaDB error log:
    Code:
      tail -10 /var/log/mysqld.log
    
    For CSF firewall LFD log:
    Code:
      tail -10 /var/log/lfd.log
    
    For Mail log:
    Code:
      tail -10 /var/log/maillog
    
    For Cron job logs:
    Code:
      tail -10 /var/log/cron
    

    How to edit php.ini and php-fpm configuration files ?



    Centmin Mod install created command short cuts outlined here to allow you to quickly edit your /usr/local/lib/php.ini file and your /usr/local/etc/php-fpm.conf file. Full list of command shortcuts below:
    • Edit php.ini = phpedit ( /usr/local/lib/php.ini )
    • Edit my.cnf = mycnf ( /etc/my.cnf )
    • Edit php-fpm.conf = fpmconf ( /usr/local/etc/php-fpm.conf )
    • Edit nginx.conf = nginxconf ( /usr/local/nginx/conf/nginx.conf )
    • Edit (nginx) virtual.conf = vhostconf - only edits /usr/local/nginx/conf/conf.d/virtual.conf not the additional vhost domain.com.conf files added later
    • Edit (nginx) php.conf = phpinc ( /usr/local/nginx/conf/php.conf )
    • Edit (nginx) drop.conf = dropinc ( /usr/local/nginx/conf/drop.conf )
    • Edit (nginx) staticfiles.conf = statfilesinc ( /usr/local/nginx/conf/staticfiles.conf )
    • nginx stop/start/restart = ngxstop/ngxstart/ngxrestart
    • php-fpm stop/start/restart = fpmstop/fpmstart/fpmrestart
    • mysql stop/start/restart = mysqlstop/mysqlstart/mysqlrestart
    • nginx + php-fpm stop/start/restart = npstop/npstart/nprestart
    • memcached stop/start/restart =memcachedstop/memcachedstart/memcachedrestart
    • csf stop/start/restart = csfstop/csfstart/csfrestart

    Troubleshooting Tools



    However, there's many linux tools and scripts that can help you figure out what was causing the load issues and when.

    Tools and commands you will want to read up on and learn for basic system admin tasks and troubleshooting.
    Notes:
    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 :)
     
    • Like Like x 1