Learn about Centmin Mod LEMP Stack today
Become a Member

Upgrade Nginx Insight Guide Developer Overview: How Nginx is installed on Centmin Mod LEMP stack

Discussion in 'Centmin Mod Insights' started by eva2000, Dec 21, 2015.

Thread Status:
Not open for further replies.
  1. eva2000

    eva2000 Administrator Staff Member

    53,149
    12,110
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,645
    Local Time:
    6:41 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    This is the first developer overview series article for Centmin Mod LEMP web stack auto installer. This first article will look at how Nginx is installed on Centmin Mod LEMP stack. If you're interested also check out how I am integrating Let's Encrypt free SSL certificates into Centmin Mod as well.

    Notes


    • You may want to bookmark this page and come back for re-reading as I update and expand on the information contained below. If you are a registered member on the forums, just watch and subscribe to this thread for notification updates ;)
    • Want to support Centmin Mod ? Please consider a donation or becoming a Centmin Mod Premium member :)

    Overview



    Nginx web server is a core component in the Centmin Mod LEMP stack responsible for serving web pages to a sites visitors. As outlined on official Nginx site page, Centmin Mod's Nginx server is source compiled as opposed to installed via CentOS YUM repositories. Source compilation allows for greater flexibility to install third party Nginx modules to extend Nginx web server's capabilities. For example, compiling against LibreSSL instead of OpenSSL and installing Google provided Nginx Pagespeed, ngx_pagespeed module as well as others listed on official Nginx site page.

    How is Nginx installed on Centmin Mod LEMP stack?



    I will be using Centmin Mod 1.2.3-eva2000.09 beta01 (123.09beta01) branch code for the following illustrative example in hopes of this article having a longer and more relevant life cycle and use centmin.sh menu option 4 - for Nginx upgrade/downgrade or recompiles for illustration.

    The heart of Centmin Mod's shell based menu, centmin.sh script when ran, gives you options 1-24 for certain automated behind the scenes tasks.

    Code (Text):
    --------------------------------------------------------
    Centmin Mod 1.2.3-eva2000.09 - http://centminmod.com
    --------------------------------------------------------
                       Centmin Mod Menu
    --------------------------------------------------------
    1).  Centmin Install
    2).  Add Nginx vhost domain
    3).  NSD setup domain name DNS
    4).  Nginx Upgrade / Downgrade
    5).  PHP Upgrade / Downgrade
    6).  XCache Re-install
    7).  APC Cache Re-install
    8).  XCache Install
    9).  APC Cache Install
    10). Memcached Server Re-install
    11). MariaDB 5.2/5.5 & 10.x Upgrade Sub-Menu
    12). Zend OpCache Install/Re-install
    13). Install ioping.sh vbtechsupport.com/1239/
    14). SELinux disable
    15). Install/Reinstall ImagicK PHP Extension
    16). Change SSHD Port Number
    17). Multi-thread compression: pigz,pbzip2,lbzip2...
    18). Suhosin PHP Extension install
    19). Install FFMPEG and FFMPEG PHP Extension
    20). NSD Re-install
    21). Update - Nginx + PHP-FPM + Siege
    22). Add Wordpress Nginx vhost + WP Super Cache
    23). Update Centmin Mod Code Base
    24). Exit
    --------------------------------------------------------
    Enter option [ 1 - 24 ] 24
    --------------------------------------------------------


    When you run centmin.sh menu option 4, you are greeted with:
    1. Question prompts as to whether you want to run yum update checks which also sync any new 3rd party yum repos I made add in future. Usually, I answer no to this.
    2. Then whether you want to continue and then what version number of Nginx you want to recompile, upgrade or downgrade i.e. Nginx 1.9.9 you would enter = 1.9.9
    Code (Text):
    --------------------------------------------------------
    Centmin Mod 1.2.3-eva2000.09 - http://centminmod.com
    --------------------------------------------------------
                       Centmin Mod Menu
    --------------------------------------------------------
    1).  Centmin Install
    2).  Add Nginx vhost domain
    3).  NSD setup domain name DNS
    4).  Nginx Upgrade / Downgrade
    5).  PHP Upgrade / Downgrade
    6).  XCache Re-install
    7).  APC Cache Re-install
    8).  XCache Install
    9).  APC Cache Install
    10). Memcached Server Re-install
    11). MariaDB 5.2/5.5 & 10.x Upgrade Sub-Menu
    12). Zend OpCache Install/Re-install
    13). Install ioping.sh vbtechsupport.com/1239/
    14). SELinux disable
    15). Install/Reinstall ImagicK PHP Extension
    16). Change SSHD Port Number
    17). Multi-thread compression: pigz,pbzip2,lbzip2...
    18). Suhosin PHP Extension install
    19). Install FFMPEG and FFMPEG PHP Extension
    20). NSD Re-install
    21). Update - Nginx + PHP-FPM + Siege
    22). Add Wordpress Nginx vhost + WP Super Cache
    23). Update Centmin Mod Code Base
    24). Exit
    --------------------------------------------------------
    Enter option [ 1 - 24 ] 4
    --------------------------------------------------------
    Custom configure CSF settings...set
    
    Do you want to run YUM install checks ?  [y/n]
    
    This will increase your upgrade duration time wise.
    Check the change log centminmod.com/changelog.html
    to see if any Nginx or PHP related new additions
    which require checking YUM prequisites are met.
    If no new additions made, you can skip the
    YUM install check to speed up upgrade time.
    
    [y/n]: n
    

    Code (Text):
    **********************************************************************
    * Nginx Update script - Included in Centmin Extras
    
    This software comes with no warranty of any kind. You are free to use
    it for both personal and commercial use as licensed under the GPL.
    Nginx Upgrade - Would you like to continue? [y/n] y
    
    Install which version of Nginx? (version i.e. 1.9.9}): 1.9.9


    When you hit enter after entering the Nginx version number 1.9.9, then the magic happens with the scripted automation for Nginx source compilation and install/upgrade/downgrade.

    Centmin Mod Include Files



    The shell script for centmin.sh is just a wrapper script that has been extended over time. Over time, the code and function routines got more involved, so I source included various include files into centmin.sh, so I can move the specific code and functions into these separate include files. These include files are usually located in inc/ directory of Centmin Mod zip downloads and end up in relative inc directory to the main Centmin Mod install directory at /usr/local/src/centminmod/inc on default Centmin Mod installs.

    Small filtered listing from inc/ directory for nginx related functions and code
    Code (Text):
    ls -lah /usr/local/src/centminmod/inc | grep nginx
    -rw-r--r--  1 root root 2.0K Dec 18 22:08 logrotate_nginx.inc
    -rw-r--r--  1 root root  21K Dec 18 22:08 nginx_addvhost.inc
    -rw-r--r--  1 root root  992 Aug 18 01:41 nginx_backup.inc
    -rw-r--r--  1 root root  32K Dec 19 00:50 nginx_configure.inc
    -rw-r--r--  1 root root 2.0K Aug 18 01:41 nginx_configure_openresty.inc
    -rw-r--r--  1 root root 1.2K Aug 18 01:41 nginx_errorpage.inc
    -rw-r--r--  1 root root  15K Dec 18 22:08 nginx_install.inc
    -rw-r--r--  1 root root 1.1K Aug 18 01:41 nginx_mimetype.inc
    -rw-r--r--  1 root root 1.4K Aug 18 01:41 nginx_modules.inc
    -rw-r--r--  1 root root 2.8K Aug 18 01:41 nginx_modules_openresty.inc
    -rw-r--r--  1 root root  19K Aug 18 01:41 nginx_pagespeed.inc
    -rw-r--r--  1 root root  867 Dec 18 22:08 nginx_patch.inc
    -rw-r--r--  1 root root  22K Dec 18 22:08 nginx_upgrade.inc


    For centmin.sh menu option 4, there are 2 main include files at work, nginx_upgrade.inc and nginx_configure.inc. The nginx_configure.inc along with nginx_install.inc is also used for the first time initial Nginx install when you first install Centmin Mod via centmin.sh menu option 1.

    You can see the latest code for Centmin Mod 123.09beta01 branch's

    nginx_upgrade.inc



    inc/nginx_upgrade.inc main called function during centmin.sh menu option 4 run is the function named = funct_nginxupgrade which when ran calls a few other functions besides just Nginx upgrading. Other functions called include:
    • gethtpasswdsh - wget downloads and installs latest htpasswd.sh script I wrote used for http basic authentication user/password generation
    • nginxbackup - every run of centmin.sh menu option 4 will backup /usr/local/nginx/conf to backup location defined in centmim.sh variable NGINXBACKUPDIR='/usr/local/nginxbackup'
    • pagespeedbackup - backup /usr/local/nginx/conf/pagespeed.conf config file with timestamped version in same directory
    • pagespeeduptasks - attempts to detect and determine if your existing pagespeed.conf and configuration differs from the current /usr/local/src/centminmod/* files defined code. If it differs, try to dynamically sync changes to update your existing pagespeed configuration with the latest code.
    • checknginxmodules - this function checks /svr-setup directory which houses all Centmin Mod downloaded required software and nginx modules to make sure the nginx module version numbers defined in centmin.sh exist at /svr-setup. If they do not exist, download them via wget
    • luajitinstall - installs LuaJit for Nginx lua modules
    • patchnginx - this function only triggers when centmin.sh variable NGINXPATCH=y - this allows you to use another include file inc/nginx_patch.inc and it's patchnginx function to code any Nginx patches you want to apply to Nginx source tarball code prior to actual Nginx compilation. This was exactly how Centmin Mod Nginx was patched for early Nginx HTTP/2 alpha patches.
    • funct_nginxconfigure - this is called from inc/nginx_configure.inc include file and is basically the configuration flags and options used for Nginx compilation and install.
    • Then there's a general routine to detect if existing Nginx installation is SPDY or HTTP/2 enabled and then to automatically reconfigure all nginx https port 443 vhost config files located in /usr/local/nginx/conf/conf.d/ to either use spdy or http2 listen directives. HTTP/2 is only reconfigured if Nginx version number is detected to be =>1.9.3 which is the version I started applying Nginx HTTP/2 alpha patch to.
    • Also checks for various include files and nginx maps being setup in /usr/local/nginx/conf/nginx.conf and /usr/local/nginx/conf/conf.d/virtual.conf. This is to make sure newer settings in newer Centmin Mod versions make it to older existing Centmin Mod installs which didn't have these newer settings and include files.

    nginx_configure.inc



    Within nginx_configure.inc include file is the main function named, funct_nginxconfigure. This is where Centmin Mod Nginx configuration options are determined. Some of which is coded to be dynamically configured depending on the Nginx related variable options you define in centmin.sh or via equivalent variable options defined in persistent overriding config file at /etc/centminmod/custom_config.inc. This allows you to customise which Nginx modules are installed or not installed with your Nginx server. Examples of this can be found in FAQ items 25 & 31.

    The funct_nginxconfigure function had this dynamic detection for which Nginx modules to include depending on Nginx variables broken down into an if or else routine based on CentOS version numbers. There was one set for CentOS 6/7 (if) and one for CentOS 5 (else) as originally Centmin Mod development started back when CentOS 5 was most common and CentOS 6 was just starting to come out. Centmin Mod now is mainly tested and used on CentOS 6 and 7, so CentOS 5 isn't really supported or tested anymore.

    You maybe confused in inc/nginx_configure.inc there is 2 sets of 2 ./configure lines listed in Centmin Mod 123.09beta01 (not in 123.08stable) as I added a new centmin.sh variable option NGXMODULE_ALTORDER=y. This is for testing an alternative Nginx module ordering configuration at configure time for better compatibility and less conflicts with various Nginx modules. Setting NGXMODULE_ALTORDER=n will go back to same Nginx module ordering scheme as Centmin mdo 123.08stable. Each of the 2 sets has one version for enabling IPv6 Nginx configuration support via detected and determined centmin.sh variable option NGINX_IPV=y|n.

    Nginx Compiler Options



    Centmin Mod 1.2.3-eva2000.08 (123.08stable) was first release to switch Nginx from using default GCC compiler to Clang. Clang was substantially faster compiler and had a lower compilation memory footprint. So Nginx right now is compiled via Clang 3.4.2. However, ngx_pagespeed 1.10 branch may change this back to GCC due to Nginx compilation issues with ngx_pagespeed 1.10 module and Clang. I am hoping Clang works eventually as it's much faster at compiling Nginx. Fixed Clang and ngx_pagespeed 1.10 compilation issue.

    Centmin Mod by default installs ccache for compiler caching. So if you are recompiling the same version number Nginx build via centmin.sh menu option 4, it will be substantially faster for source compile times. Benchmark tests have revealed around 60-80% faster recompile times.

    Nginx Upgrade Error Checking



    The nginx_upgrade.inc include file's funct_nginxupgrade function also includes Nginx upgrade error checking at both the configure, make and make install stages. This error checking just serves to better pinpoint failures or errors at configure, make and make install stages and timestamp them with a clearer error message. This can make troubleshooting easier when you delve into the centmin.sh menu option automatically logged diagnostic files which I will touch on next.


    Nginx Upgrade Logging



    As per FAQ item 7, every centmin.sh menu option ran will have it's own timestamped log file saved at /root/centminlogs and it's location is defined by centmin.sh variable CENTMINLOGDIR='/root/centminlogs'. If you have errors with Nginx upgrade/downgrade or recompiling, this will be the first location to look at for the nginx_upgrade.log for your centmin.sh menu option 4 run

    /root/centminlogs listed in ascending date order
    Code (Text):
    ls -lArt /root/centminlogs/
    total 8228
    -rw-r--r-- 1 root root   14762 Aug 16 23:33 centminmod_1.2.3-eva2000.09_170815-093315_yuminstall_centos6.log
    -rw-r--r-- 1 root root   38879 Aug 16 23:35 centminmod_yumtimes_170815-093315.log
    -rw-r--r-- 1 root root      38 Aug 16 23:35 centminmod_profiletimes_170815-093315.log
    -rw-r--r-- 1 root root       0 Aug 16 23:35 timedhosts_170815-093315.txt
    -rw-r--r-- 1 root root  226274 Aug 16 23:36 centminmod_downloadtimes_170815-093315.log
    -rw-r--r-- 1 root root    1444 Aug 16 23:36 securedtmp.log
    -rw-r--r-- 1 root root      45 Aug 16 23:38 centminmod_libresslinstalltime_170815-093315.log
    -rw-r--r-- 1 root root  962310 Aug 16 23:42 centminmod_ngxinstalltime_170815-093315.log
    -rw-r--r-- 1 root root      58 Aug 16 23:48 centminmod_phpinstalltime_170815-093315.log
    -rw-r--r-- 1 root root     382 Aug 16 23:48 zendopcache_passfile.txt
    -rw-r--r-- 1 root root    1468 Aug 16 23:53 centminmod_1.2.3-eva2000.09_170815-093315_yum-log.log
    -rw-r--r-- 1 root root      20 Aug 16 23:53 install.utc.time.log
    -rw-r--r-- 1 root root 2711440 Aug 16 23:53 centminmod_1.2.3-eva2000.09_170815-093315_install.log
    -rw-r--r-- 1 root root      48 Aug 16 23:53 firstyum_installtime_170815-093132.log
    -rw-r--r-- 1 root root    1693 Aug 18 01:41 centminmod_1.2.3-eva2000.09_180815-014045_git_envsetup.log
    -rw-r--r-- 1 root root      45 Dec 18 22:14 centminmod_libresslinstalltime_181215-221055.log
    -rw-r--r-- 1 root root  952872 Dec 18 22:16 centminmod_1.2.3-eva2000.09_181215-221055_nginx_upgrade.log
    -rw-r--r-- 1 root root      44 Dec 19 00:10 centminmod_libresslinstalltime_191215-000953.log
    -rw-r--r-- 1 root root  776351 Dec 19 00:12 centminmod_1.2.3-eva2000.09_191215-000953_nginx_upgrade.log
    -rw-r--r-- 1 root root      44 Dec 19 00:18 centminmod_libresslinstalltime_191215-001728.log
    -rw-r--r-- 1 root root  776498 Dec 19 00:19 centminmod_1.2.3-eva2000.09_191215-001728_nginx_upgrade.log
    -rw-r--r-- 1 root root      44 Dec 19 00:28 centminmod_libresslinstalltime_191215-002655.log
    -rw-r--r-- 1 root root   41615 Dec 19 00:28 centminmod_1.2.3-eva2000.09_191215-002655_nginx_upgrade.log
    -rw-r--r-- 1 root root      44 Dec 19 00:32 centminmod_libresslinstalltime_191215-003142.log
    -rw-r--r-- 1 root root  196662 Dec 19 00:33 centminmod_1.2.3-eva2000.09_191215-003142_nginx_upgrade.log
    -rw-r--r-- 1 root root      44 Dec 19 00:35 centminmod_libresslinstalltime_191215-003429.log
    -rw-r--r-- 1 root root  728317 Dec 19 00:37 centminmod_1.2.3-eva2000.09_191215-003429_nginx_upgrade.log
    -rw-r--r-- 1 root root      44 Dec 19 00:51 centminmod_libresslinstalltime_191215-005014.log
    -rw-r--r-- 1 root root     750 Dec 19 00:52 gcc_native.log
    -rw-r--r-- 1 root root  888446 Dec 19 00:55 centminmod_1.2.3-eva2000.09_191215-005014_nginx_upgrade.log
    

    filter just for nginx_upgrade.log logs
    Code (Text):
    ls -lArt /root/centminlogs/ | grep nginx_upgrade
    -rw-r--r-- 1 root root  952872 Dec 18 22:16 centminmod_1.2.3-eva2000.09_181215-221055_nginx_upgrade.log
    -rw-r--r-- 1 root root  776351 Dec 19 00:12 centminmod_1.2.3-eva2000.09_191215-000953_nginx_upgrade.log
    -rw-r--r-- 1 root root  776498 Dec 19 00:19 centminmod_1.2.3-eva2000.09_191215-001728_nginx_upgrade.log
    -rw-r--r-- 1 root root   41615 Dec 19 00:28 centminmod_1.2.3-eva2000.09_191215-002655_nginx_upgrade.log
    -rw-r--r-- 1 root root  196662 Dec 19 00:33 centminmod_1.2.3-eva2000.09_191215-003142_nginx_upgrade.log
    -rw-r--r-- 1 root root  728317 Dec 19 00:37 centminmod_1.2.3-eva2000.09_191215-003429_nginx_upgrade.log
    -rw-r--r-- 1 root root  888446 Dec 19 00:55 centminmod_1.2.3-eva2000.09_191215-005014_nginx_upgrade.log


    Verify Nginx Install/Upgrade



    To verify once Nginx is upgraded/downgraded or recompiled, you can run 2 commands
    Code (Text):
    nginx -V
    ngxrestart

    First command lists Nginx version number along with all the Nginx modules configured for your Nginx server
    Second command is a Centmin Mod command shortcut outlined in FAQ item 16 to restart Nginx service/server.
    Code (Text):
    ngxrestart
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    Stopping nginx:                                            [  OK  ]
    Starting nginx:  


    Below are a list of command shortcuts:
    • 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
     
    Last edited: Oct 18, 2016
Thread Status:
Not open for further replies.