一、查看nginx安裝過的模塊
如果我們已經安裝了nginx,那麼我們可以通過以下命令來查看nginx的編譯參數,從而知道nginx安裝了哪些模塊:
nginx -V
執行該命令後,就會顯示nginx的編譯參數信息,其中會包含許多模塊:
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream_ssl_module --with-stream=dynamic --with-stream_ssl_preread_module --with-pcre --with-pcre-jit --with-openssl=/builddir/build/BUILD/nginx-1.14.2/openssl-1.0.2k --add-module=/builddir/build/BUILD/nginx-1.14.2/njs/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_addition_module --with-http_geoip_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_ssl_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/nginx-upstream-hash --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/nginx-fancyindex --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/nginx-auth-ldap --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/ngx_cache_purge --add-dynamic-module=/usr/local/src/incubator-pagespeed-ngx-1.13.35.2-stable
二、查看nginx安裝的模塊
如果我們需要查看nginx確切已安裝的模塊,可以通過以下命令查詢:
nginx -V 2>&1 | grep modules
執行該命令後,就會顯示nginx已安裝的模塊:
--modules-path=/usr/lib64/nginx/modules --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-openssl=/builddir/build/BUILD/nginx-1.14.2/openssl-1.0.2k --add-module=/builddir/build/BUILD/nginx-1.14.2/njs/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_addition_module --with-http_geoip_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/nginx-upstream-hash --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/nginx-fancyindex --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/nginx-auth-ldap --add-dynamic-module=/builddir/build/BUILD/nginx-1.14.2/modules/ngx_cache_purge --add-dynamic-module=/usr/local/src/incubator-pagespeed-ngx-1.13.35.2-stable
三、查看nginx已安裝模塊
如果我們需要快速查看nginx已安裝的模塊,可以使用以下命令直接列出nginx已安裝的模塊:
ls /usr/lib64/nginx/modules/
執行該命令後,就會列出已經安裝好的nginx模塊:
ngx_http_geoip_module.so ngx_stream_upstream_module.so ngx_stream_ssl_preread_module.so ngx_stream_ssl_module.so ngx_stream_realip_module.so ngx_stream_dubbo_module.so ngx_stream_core_module.so ngx_http_xslt_filter_module.so ngx_http_v2_module.so ngx_http_upstream_module.so ngx_http_sub_module.so ngx_http_slice_module.so ngx_http_set_misc_module.so ngx_http_secure_link_module.so ngx_http_realip_module.so ngx_http_proxy_module.so ngx_http_perl_module.so ngx_http_mp4_module.so ngx_http_js_module.so ngx_http_image_filter_module.so ngx_http_geoip2_module.so ngx_http_gzip_static_module.so ngx_http_fancyindex_module.so ngx_http_dav_module.so ngx_http_degradation_module.so ngx_http_addition_module.so ngx_http_auth_request_module.so
四、nginx有哪些模塊
nginx官方提供了許多模塊,可以通過源碼安裝,安裝過程中可以選擇需要的模塊。這些模塊包括:
- HTTP模塊
- ngx_http_realip_module
- ngx_http_addition_module
- ngx_http_xslt_module
- ngx_http_image_filter_module
- ngx_http_geoip_module
- ngx_http_sub_module
- ngx_http_dav_module
- ngx_http_flv_module
- ngx_http_mp4_module
- ngx_http_random_index_module
- ngx_http_secure_link_module
- ngx_http_degradation_module
- ngx_http_slice_module
- ngx_http_stub_status_module
- ngx_http_ssl_module
- ngx_http_v2_module
- ngx_http_gzip_static_module
- ngx_http_auth_request_module
- ngx_http_perl_module(第三方模塊)
- ngx_http_js_module(第三方模塊)
- Mail模塊
- ngx_mail_ssl_module
- Stream模塊
- ngx_stream_ssl_module
- ngx_stream_realip_module
- ngx_stream_geoip_module
- ngx_stream_ssl_preread_module
- ngx_stream_limit_conn_module
- ngx_stream_limit_req_module
五、nginx查看已安裝模塊
如果我們在安裝時選擇了某個模塊,但不確定是否已經成功安裝可以通過以下命令來查看:
nginx -V 2>&1 | grep module_name
其中「module_name」指的是模塊的名稱。如果輸出結果中包含該模塊的信息,則說明該模塊已經被成功安裝。
六、nginx安裝ssl模塊
ssl模塊是用於支持https協議的模塊。nginx中默認開啟了ssl模塊,如果在編譯安裝nginx時沒有開啟ssl模塊,那麼需要重新編譯nginx,並在編譯選項中添加「–with-http_ssl_module」參數。具體安裝步驟如下:
- 下載nginx源碼(https://nginx.org/en/download.html),解壓後進入nginx源碼目錄。
- 執行以下命令,安裝編譯依賴及PCRE和OpenSSL:
- 執行以下命令執行編譯及安裝:
- 安裝完成後,執行以下命令啟動nginx:
yum install gcc gcc-c++ make zlib-devel pcre pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
/usr/local/nginx/sbin/nginx
七、nginx安裝lua模塊
lua模塊是用於支持Lua腳本的模塊。在編譯安裝nginx時需要添加「–with-http_lua_module」參數。具體安裝步驟如下:
- 下載nginx源碼(https://nginx.org/en/download.html),解壓後進入nginx源碼目錄。
- 安裝luajit:
- 執行以下命令安裝編譯依賴:
- 執行以下命令以編譯nginx:
- 可以通過以下命令測試Lua是否工作正常:
yum install -y git gcc make readline-devel ncurses-devel
git clone https://github.com/openresty/luajit2.git
cd luajit2
make && make install
yum install -y gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/path/to/lua-nginx-module
curl http://localhost/test.lua
八、nginx支持哪些常用模塊
nginx默認支持的常用模塊:
- HTTP模塊:
- ngx_http_realip_module:實現客戶端IP地址的獲取和替換
- ngx_http_addition_module:支持在文件中添加自定義頭和尾
- ngx_http_xslt_module:支持對後端返回的XML格式內容進行XSLT操作
- ngx_http_image_filter_module:支持在nginx內置生成縮略圖
- ngx_http_geoip_module:獲取客戶端地理位置
- ngx_http_google_filter_module:支持將谷歌搜索結果內嵌至頁面
- ngx_http_sub_module:實現內容替換功能
- ngx_http_dav_module:配置WebDAV
- ngx_http_flv_module:支持Flv流輸出
- ngx_http_mp4_module:支持Mp4文件流輸出
- ngx_http_random_index_module:支持目錄隨機頁面
- ngx_http_secure_link_module:生成安全鏈接
- ngx_http_slice_module:支持文件分塊下載
- ngx_http_degradation_module:實現頁面降級
- ngx_http_slice_module:支持文件分塊下載
- ngx_http_stub_status_module:提供nginx狀態信息
- ngx_http_ssl_module:支持SSL協議
- ngx_http_v2_module:支持HTTP2協議
- ngx_http_gzip_static_module:開啟Gzip功能
- ngx_http_auth_request_module:實現簡單的認證功能
- ngx_http_perl_module(第三方):集成Perl解釋
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/279651.html