how to view loaded modules in nginx
command
nginx-V
it will list nginx version with compiled modules, while installing a module.
static modules:
installed along with nginx install, no way to disable or enable like Apache.
dynamic modules:
available in nginx plus and newer nginx version.
step 1: compile nginx module in same environment like production server.
2nd: test server: used to compile the module. after compiled module available,
3rd: we have to copy the module end .so
/etc/nginx/modules (or other path).
and include in nginx.conf
Loadmodule /path/to-module
nginx module instead of error fix.
if you are using this dynamic module, you will get this (,upgrade failed).
because dynamic module has to recompile along with new nginx version.
/etc/nginx/modules/ngx_http_geoip_module.so
don’t restart or reboot(if nginx unable to start until problem fixed)
temporary fix: unload module by commenting in nginx.conf & start the upgrade
permanent fix: recompile the module with new nginx version /current nginx version.
how to install dynamic module in nginx?
check your nginx version
nginx -v
or upgrade to latest version.
then type nginx -v
download latest version of nginx it should match current production server
#1 download nginx
wget -qO – http://nginx.org/download/nginx-1.18.10.tar.gz | tar zxfv –
#2 download dynamic module
#2.1 install build tools if not already
sudo apt-get install unzip gcc make libpcre3-dev zlib1g-dev
#3 compile dynamic module
company & make modules command
cd nginx-1.11.10/
./configure –with-compat –add-dynamic-module=../nginx-hello-world-module
$ make modules
#4. verify the module & copy to nginx directory
by default its available in objs subdirectory
ls objs/*.so
objs/ngx_http_hello_world.so
cp objs/ngx_http_hello_world.so /etc/nginx/modules
#5 upgrade nginx if not done early
service nginx upgrade
#6 edit nginx.conf
loadmodule
,& reload nginx
if you are building it in production server.
it’s better to compile in build environment & copy to production server.
mycase: I already did in production server (but downtime important in case of high traffic)
enable & disable dynamic module in nginx
edit conf file
comment or uncomment
reload nginx server.
also read pagespeed module in nginx as dynamic.
module configuration file would be in nginx.conf or
conf.d modulename.conf
nginx modules location
static modules
–modules-path=/usr/lib/nginx/modules
dynamic module /etc/nginx/modules (shortcut to usr/lib/nginx)
Install nginx without unnecessary modules
Note: every module has some features, and runs in memory (so uninstall unnecessary modules or install with required module)
–without-module
Lets know about some useful nginx modules
Nginx http core module
Module ngx_http_core_module
Keepalive
client body, head buffers
etag, if modified since etc
more at here
nginx fastcgi module
fastcgi read timeout to fix 504 timeout nginx
buffers etc.
nginx proxy module
proxy modules and fastcgi directives and variables are same. starts fastcgi_ instead proxy_
proxy module used to backend serer ex use nginx as reverse proxy and load balancer for apache wordpress
all 3 aboe modules necessary to run a nginx server and installed by default with nginx.
Memcached & redis modules also available
best modules for nginx third party
WAF security firewall: securing the serer
Pagespeed module for dynamic page optimization
Redis module for object cache
Brotli better than gzip by google
cache purge: ability to purge fastcgi cache
more here
how to enable brotli compression in nginx
$ apt-get install nginx-plus-module-brotli
edit nginx.conf
at top:
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
configurations in .conf
same as gzip just replacewith brotil.
read more here
____&_____&____&_____&
root@instance-1:~# nginx -V
nginx version: nginx/1.13.8
built by gcc 6.3.0 20170516 (Debian 6.3.0-18)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
configure arguments: –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –modules-p ath=/usr/lib/nginx/modules –conf-path=/etc/nginx/nginx.conf –error-log-path=/v ar/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var /run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var /cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –ht tp-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/c ache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=ng inx –group=nginx –with-compat –with-file-aio –with-threads –with-http_addit ion_module –with-http_auth_request_module –with-http_dav_module –with-http_fl v_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp 4_module –with-http_random_index_module –with-http_realip_module –with-http_s ecure_link_module –with-http_slice_module –with-http_ssl_module –with-http_st ub_status_module –with-http_sub_module –with-http_v2_module –with-mail –with -mail_ssl_module –with-stream –with-stream_realip_module –with-stream_ssl_mod ule –with-stream_ssl_preread_module –with-cc-opt=’-g -O2 -fdebug-prefix-map=/d ata/builder/debuild/nginx-1.13.8/debian/debuild-base/nginx-1.13.8=. -specs=/usr/ share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format -security -Wp,-D_FORTIFY_SOURCE=2 -fPIC’ –with-ld-opt=’-specs=/usr/share/dpkg/n o-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,–as-needed -pie’
root@instance-1:~#
Nginx modules which are installed by default
./configure
–prefix=/etc/nginx \
–sbin-path=/usr/sbin/nginx \
–modules-path=/usr/lib/nginx/modules \
–conf-path=/etc/nginx/nginx.conf \
–error-log-path=/var/log/nginx/error.log \
–http-log-path=/var/log/nginx/access.log \
–pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock \
–http-client-body-temp-path=/var/cache/nginx/client_temp \
–http-proxy-temp-path=/var/cache/nginx/proxy_temp \
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
–http-scgi-temp-path=/var/cache/nginx/scgi_temp \
–user=nginx –group=nginx \
–add-module=/root/incubator-pagespeed-ngx-latest-stable \
–with-compat \
–with-file-aio \
–with-threads \
–with-http_addition_module \
–with-http_auth_request_module \
–with-http_dav_module \
–with-http_flv_module \
–with-http_gunzip_module \
–with-http_gzip_static_module \
–with-http_mp4_module \
–with-http_random_index_module \
–with-http_realip_module \
–with-http_secure_link_module \
–with-http_slice_module \
–with-http_ssl_module \
–with-http_sub_status_module \
–with-http_sub_module \
–with-http_v2_module –with-mail \
–with-mail_ssl_module \
–with-stream \
–with-stream_realip_module \
–with-stream_ssl_module \
–with-stream_ssl_preread_module \
–with-cc-opt=’-g -O2 \
configure arguments: –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –modules-p ath=/usr/lib/nginx/modules –conf-path=/etc/nginx/nginx.conf –error-log-path=/v ar/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var /run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var /cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –ht tp-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/c ache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=ng inx –group=nginx –with-compat –with-file-aio –with-threads –with-http_addit ion_module –with-http_auth_request_module –with-http_dav_module –with-http_fl v_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp 4_module –with-http_random_index_module –with-http_realip_module –with-http_s ecure_link_module –with-http_slice_module –with-http_ssl_module –with-http_st ub_status_module –with-http_sub_module –with-http_v2_module –with-mail –with -mail_ssl_module –with-stream –with-stream_realip_module –with-stream_ssl_mod ule –with-stream_ssl_preread_module –with-cc-opt=’-g -O2 -fdebug-prefix-map=/d ata/builder/debuild/nginx-1.13.9/debian/debuild-base/nginx-1.13.9=. -specs=/usr/ share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format -security -Wp,-D_FORTIFY_SOURCE=2 -fPIC’ –with-ld-opt=’-specs=/usr/share/dpkg/n o-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,–as-needed -pie’
How do I see what modules are installed in nginx?
just run this command
sudo nginx -V
What are dynamic modules in nginx?
apache more mature you can add new module just by one click. but with nginx you have to recompile nginx.
to overcome this nginx plus added a new feature called dynamic module. compiled version of file with same linux and nginx server. we can enable disable any time.
i tried pagespeed nginx module. later removed.