1. 程式人生 > 實用技巧 >3,為nginx啟用ngx_http_v2_module模組

3,為nginx啟用ngx_http_v2_module模組

生產環境的nginx當初沒有編譯啟用ngx_http_v2_module模組

[root@nginx51 ~]# /opt/nginx/sbin/nginx -V
nginx version: nginx/1.12.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --user=nginx --group=nginx --with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module --with-pcre=/tmp/pcre-8.40
--with-stream

現在業務上要用到這個模組,需要把它重新編譯進去但不影響業務

步驟:

進入到nginx原始碼目錄重新編譯,通過--with-http_v2_module啟用ngx_http_v2_module模組,然後make (注意不要make install,否則直接覆蓋了)

cd /tmp/nginx-1.12.0                # nginx原始碼版本必須和當前生產環境的nginx一致
./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module --with-pcre=/tmp/pcre-8.40
--with-stream --with-http_v2_module make

meke好了之後會在原始碼目錄下的objs目錄產生nginx的二進位制,先不要make install

[root@nginx51 objs]# cd /tmp/nginx-1.12.0/objs/
[root@nginx51 objs]# ls
autoconf.err  Makefile  nginx  nginx.8  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  ngx_modules.o  src

然後把原先的nginx二進位制命令備份,用上面編譯好的nginx替換,最後reload的nignx就可以

[root@nginx51 ~]# cd /opt/nginx/sbin/
[root@nginx51 sbin]# mv nginx nginx.bak                 # 備份
[root@nginx51 sbin]# cp /tmp/nginx-1.12.0/objs/nginx .  # 把編譯好的nginx拷貝過來
[root@nginx51 sbin]# service nginx reload               # 過載nginx

在通過nginx -V測試,可以看到--with-http_v2_module,說明ok了

[root@nginx51 sbin]# /opt/nginx/sbin/nginx -V
nginx version: nginx/1.12.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --user=nginx --group=nginx 
--with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module 
--with-pcre=/tmp/pcre-8.40 --with-stream --with-http_v2_module

其它模組的啟用也是類似的。順便說下make和make install, make是把原始碼編譯成可執行的二進位制,make install是把編譯好的二進位制或一些檔案安裝到指定的路徑.

另外nginx1.10版本可以動態新增模組