CentOS7.6下安裝nginx1.20.1及nginx動態模塊使用


需求說明

  1. 在系統中安裝nginx1.20.1
  2. 動態引入stream模塊

配置步驟

下載編譯源碼包

  1. 下載源碼包到指定的目錄,本次目錄是在/u01下
wget http://nginx.org/download/nginx-1.20.1.tar.gz
  1. 解壓並編譯源碼

本次編譯的時候指定使用http_stub_status_module和http_ssl_module

tar -zxvf  nginx-1.20.1.tar.gz
cd nginx-1.20.1/

配置編譯使用的模塊

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

編譯

make
make install
  1. 進入目錄,測試訪問
cd /usr/local/nginx/sbin/
./nginx
curl localhost

編譯stream模塊

  1. 進入之前下載解壓后的源碼包內
cd /u01/nginx-1.20.1/
  1. 查看nginx支持的動態模塊
[root@load-eco nginx-1.20.1]# ./configure --help | grep dynamic
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module
  --with-http_image_filter_module=dynamic
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module
  --with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module
  --with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module
  --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  --add-dynamic-module=PATH          enable dynamic external module
  --with-compat                      dynamic modules compatibility

  1. 編譯指定模塊
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream=dynamic

注意,此時只需要make即可,不要執行make install

make
  1. 復制編譯后的模塊文件

在編譯后,在/u01/nginx-1.20.1/objs中會有編譯好的 ngx_stream_module.so模塊,此時只需要將模塊復制到nginx的工作目錄即可,如果在nginx目錄中沒有modules也可以自己建立一個

cp ngx_stream_module.so    nginx_worker_dir/modules/
  1. 修改nginx.conf配置文件,載入模塊
load_module  modules/ngx_stream_module.so;

stream {
   ....
}

  1. 新加載配置

官方介紹

https://nginx.org/en/docs/configure.html
https://nginx.org/en/docs/stream/ngx_stream_core_module.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM