Learn about Centmin Mod LEMP Stack today
Register Now

Beta Branch Add NGXDYNAMIC_VHOSTSTATS option support for nginx-module-vts module

Discussion in 'Centmin Mod Github Commits' started by eva2000, Sep 22, 2017.

  1. eva2000

    eva2000 Administrator Staff Member

    30,634
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,308
    Local Time:
    1:54 PM
    Nginx 1.13.x
    MariaDB 5.5
    Add NGXDYNAMIC_VHOSTSTATS option support for nginx-module-vts module

    - Add support for nginx-module-vts virtual host traffic status nginx module https://github.com/vozlt/nginx-module-vts to be compiled as a dynamic nginx module instead of static nginx module when persistent config file /etc/centminmod/custom_config.inc is set with variables NGXDYNAMIC_VHOSTSTATS='y' and NGINX_VHOSTSTATS='y' (both disabled by default in 123.09beta01). Then recompile nginx via centmin.sh menu option 4

    Continue reading...

    123.09beta01 branch
     
    Last edited: Sep 22, 2017
  2. eva2000

    eva2000 Administrator Staff Member

    30,634
    6,862
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,308
    Local Time:
    1:54 PM
    Nginx 1.13.x
    MariaDB 5.5
    FAQ item 39 has general explanation of how nginx dynamic modules work on Centmin Mod 123.09beta01+ and higher's Nginx server.

    persistent config file /etc/centminmod/custom_config.inc is set with variables + recompile nginx via centmin.sh menu option 4
    Code (Text):
    NGXDYNAMIC_VHOSTSTATS='y'
    NGINX_VHOSTSTATS='y'
    

    the end result is nginx-module-vts nginx module compiled as a dynamic nginx module = --add-dynamic-module=../nginx-module-vts
    In dynamic nginx module include conf file at /usr/local/nginx/conf/dynamic-modules.conf has following contents:
    Code (Text):
    # place custom load_module lines in this dynamic-modules-includes.conf
    # file so that they persistent i.e. for manually dropped in dynamic modules
    include /usr/local/nginx/conf/dynamic-modules-includes.conf;
    load_module "modules/ngx_http_image_filter_module.so";
    load_module "modules/ngx_http_headers_more_filter_module.so";
    load_module "modules/ngx_http_set_misc_module.so";
    load_module "modules/ngx_http_echo_module.so";
    load_module "modules/ngx_http_fancyindex_module.so";
    load_module "modules/ngx_http_vhost_traffic_status_module.so";
    load_module "modules/ngx_stream_module.so";

    Notice the include file within it at /usr/local/nginx/conf/dynamic-modules-includes.conf, that is so you can drop in dynamic nginx modules that persistent as the /usr/local/nginx/conf/dynamic-modules.conf is rebuilt each time nginx recompiles. Nginx dynamic modules allow you to load and enable nginx modules without recompiling Nginx but the dynamic module needs to build with same version of Nginx and for Centmin Mod's purpose same or similar server cpu in some circumstances. So if you have a staging server with indentical Centmin Mod Nginx version, you could technically build and enable the dynamic nginx module on staging server and then copy it over to servers you want to enable the module at /usr/local/nginx/modules and in the include file at /usr/local/nginx/conf/dynamic-modules-includes.conf set the load_module line. So for example if your want to copy over nginx-module-vts dynamic module, you would copy to /usr/local/nginx/modules/ngx_http_vhost_traffic_status_module.so and in /usr/local/nginx/conf/dynamic-modules-includes.conf setup
    Code (Text):
    load_module "modules/ngx_http_vhost_traffic_status_module.so";
    

    If you do copy over a dynamic nginx module from a staging server to live etc, then make sure live server (destination server of dynamic nginx module copy), has NGXDYNAMIC_VHOSTSTATS='n' and NGINX_VHOSTSTATS='n' set otherwise, nginx recompiles in future may complain of duplicate dynamic module loading - one from manually setup persistent load_module line + one from nginx dynamically built include file at /usr/local/nginx/conf/dynamic-modules.conf.

    dynamic module directory at /usr/local/nginx/modules the nginx-module-vts dynamic module = ngx_http_vhost_traffic_status_module.so
    Code (Text):
    -rwxr-xr-x   1 root root 185K Sep 21 18:00 ngx_http_echo_module.so
    -rwxr-xr-x   1 root root 185K Sep  9 06:17 ngx_http_echo_module.so.old
    -rwxr-xr-x   1 root root  52K Sep 21 18:00 ngx_http_fancyindex_module.so
    -rwxr-xr-x   1 root root  52K Sep  9 06:17 ngx_http_fancyindex_module.so.old
    -rwxr-xr-x   1 root root  89K Sep 21 18:00 ngx_http_headers_more_filter_module.so
    -rwxr-xr-x   1 root root  89K Sep  9 06:17 ngx_http_headers_more_filter_module.so.old
    -rwxr-xr-x   1 root root  55K Sep 21 18:00 ngx_http_image_filter_module.so
    -rwxr-xr-x   1 root root  55K Sep  9 06:17 ngx_http_image_filter_module.so.old
    -rwxr-xr-x   1 root root 200K Sep 21 18:00 ngx_http_set_misc_module.so
    -rwxr-xr-x   1 root root 200K Sep  9 06:17 ngx_http_set_misc_module.so.old
    -rwxr-xr-x   1 root root 373K Sep 21 18:00 ngx_http_vhost_traffic_status_module.so
    -rwxr-xr-x   1 root root 447K Sep 21 18:00 ngx_stream_module.so
    -rwxr-xr-x   1 root root 447K Sep  9 06:17 ngx_stream_module.so.old
    

    In your main hostname's Nginx vhost which you setup in Getting Started Guide Step 1 at /usr/local/nginx/conf/conf.d/virtual.conf you will have a include file for nginx-module-vts at /usr/local/nginx/conf/vts_mainserver.conf containing something like below where you need to add your own ISP IP address to whitelist it replacing YOURISP_IPADDR and make sure the 3 vhost_traffic_status directives are not commented out with hash in front.
    Code (Text):
    location /vhost_status {
        allow 127.0.0.1;
        allow YOURISP_IPADDR;
        deny all;
        vhost_traffic_status on;
        vhost_traffic_status_display;
        vhost_traffic_status_display_format html;
    }
    
    location = /vhost_status.html {
        allow 127.0.0.1;
        allow YOURISP_IPADDR;
        deny all;
    }
    

    Then visit your main hostname's domain i.e. host.domain.com/vhost_status which will have nginx vhost traffic statistics which are live but don't persistent and survive nginx restarts unless you configure it to do so as outlined here. In /usr/local/nginx/conf/nginx.conf there is an include file at /usr/local/nginx/conf/vts_http.conf. Edit /usr/local/nginx/conf/vts_http.conf and add the line for vhost_traffic_status_dump directive.
    Code (Text):
    vhost_traffic_status_zone;
    vhost_traffic_status_dump /var/log/nginx/vts.db;
    

    create the file + restart nginx
    Code (Text):
    touch /var/log/nginx/vts.db
    chown nginx /var/log/nginx/vts.db
    ngxrestart
    



    nginx-module-vts-220917-01.png
     
    Last edited: Sep 22, 2017