Thêm module mới cho NGINX đã được cài đặt

Thêm module mới cho NGINX đã được cài đặt

Để bổ sung thêm module cho NGINX mà không cần biên dịch lại từ đầu, bạn cần thực hiện theo các bước sau đây.

Bước 1: Kiểm tra thông tin NGINX hiện tại

Sử dụng lệnh sau để xem thông tin chi tiết của NGINX đã cài đặt:

nginx -V

Thông tin cần quan tâm bao gồm:

  • Phiên bản NGINX: 1.14.1
  • Các tham số configure đã được sử dụng

Ví dụ về các tham số configure:

--prefix=/etc/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 --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 --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_stub_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='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

Bước 2: Tải mã nguồn NGINX

Tải mã nguồn cùng phiên bản với NGINX đã cài đặt từ:

http://nginx.org/en/download.html

Giải nén và di chuyển vào thư mục mã nguồn:

cd nginx-1.14.1

Bước 3: Tải và cấu hình module mới

Tải mã nguồn của module cần thêm và đặt trong cùng thư mục với thư mục mã nguồn NGINX. Sau đó thực hiện configure với các tham số cũ và thêm module mới:

./configure --prefix=/etc/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 --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 --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_stub_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='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=../nginx-rtmp-module-1.2.1

Tham số --add-module=../nginx-rtmp-module-1.2.1 là module cần thêm vào.

Bước 4: Biên dịch NGINX

Sau khi configure hoàn tất, thực hiện biên dịch:

make

Lưu ý: Không chạy lệnh make install vì điều này sẽ ghi đè toàn bộ cài đặt hiện tại. File NGINX sau biên dộng nằm trong thư mục objs.

Bước 5: Thay thế file binary NGINX

Sao lưu file NGINX hiện tại:

cp /usr/sbin/nginx /usr/sbin/nginx.backup

Di chuyển file binary mới biên dịch vào vị trí:

cp objs/nginx /usr/sbin/nginx

Bước 6: Khởi động lại NGINX

Dừng và khởi động lại dịch vụ NGINX:

nginx -s stop
nginx

Bước 7: Xác nhận module đã được thêm

Kiểm tra lại thông tin NGINX để xác nhận module đã được tích hợp:

nginx -V

Danh sách các module sẽ hiển thị module mới đã được thêm vào.

Thẻ: nginx module web-server Configuration compile

Đăng vào ngày 30 tháng 6 lúc 00:48