Hướng dẫn nâng cấp Nginx lên version 1.9.11
hỗ trợ giao thức HTTP/2 trên Direct Admin
Bài viết này sẽ hướng dẫn các bạn sử dụng Direct Admin update Nginx lên phiên bản 1.9.11 mới để hỗ trợ tính năng giao thức HTTP/2 tận dụng khả năng ưu việt của nó. Nginx công bố việc hỗ trợ giao thức HTTP/2 từ phiên bản 1.9.5 trở đi, nên ta sẽ sử dụng source phiên bản 1.9.11 mới để kích hoạt tính năng hỗ trợ giao thức HTTP/2.
Hiện tại Direct Admin cho phép hỗ trợ sử dụng download phiên bản Nginx mainline mới cài đặt tính đến thời điểm hiện tại (3/2016) là Nginx v1.9.11 . (dù vậy trên trang chủ Nginx đã ra phiên bản 1.9.12, nhưng do source download DA hiện tại kiểm tra chỉ có v1.9.11).
Bản thân Direct Admin Custombuild 2 mặc định vẫn sẽ sử dụng phiên bản Nginx stable 1.8.1 nhưng phiên bản 1.8.x hoàn toàn không hỗ trợ chức năng giao thức HTTP/2 trên Nginx.
Điều kiện cần :
– Sử dụng Custombuild 2, nếu vẫn xài phiên bản cũ thì update lên.
– Mode web_server khi build Direct Admin phải là Nginx hoặc Nginx_Apache (Nginx reverse proxy Apache).
– Download phiên bản OpenSSL 1.0.2 để compile cùng Nginx.
Thực hiện
1. Tạo file script để thực hiện công việc rebuild Nginx version mainline
– Thực hiện các thao tác cần thiết tạo file script.
# rm -f /usr/local/directadmin/custombuild/build_nginx-custom # touch /usr/local/directadmin/custombuild/build_nginx-custom # chmod 755 /usr/local/directadmin/custombuild/build_nginx-custom
– Ở đây bạn sẽ lưu ý phần chỉnh sửa lại phía dòng cuối đoạn shell script, lựa chọn build theo mode “nginx” đứng 1 mình làm web server hay “nginx_apache” reverse proxy. Điều này phụ thuộc hệ thống của bạn đang chạy ra sao hoặc quyết định ngay từ khi build.
– Ở bài hướng dẫn này, mình sử dụng mode ví dụ “nginx_apache” , các bạn có thể thay đổi theo hệ thống các bạn.
+ “Nginx” standalone.
./build nginx
+ “nginx_apache” Nginx reverse proxy Apache
./build nginx_apache
– Tạo nội dung shell script.
# vi /usr/local/directadmin/custombuild/build_nginx-custom
#!/bin/bash NGINX_VER=1.9.11 cd /usr/local/directadmin/custombuild cat custom_versions.txt | grep -Ev "^nginx:|^$" > custom_versions.txt.new mv -f custom_versions.txt.new custom_versions.txt echo "nginx:${NGINX_VER}:" >> custom_versions.txt wget http://nginx.org/download/nginx-${NGINX_VER}.tar.gz -O nginx-${NGINX_VER}.tar.gz ./build update ./build nginx_apache exit 0
– Lúc này bạn chưa được chạy script nhé. Làm thêm các bước sau đây.
2. Chỉnh sửa file compile source Nginx để kích hoạt giao thức hỗ trợ HTTP/2
– Đầu tiên ta cần download source OpenSSL 1.0.2g.
# cd /usr/local/src/ # wget -O /usr/local/src/openssl-1.0.2g.tar.gz https://www.openssl.org/source/openssl-1.0.2g.tar.gz # mkdir -p /usr/local/src/openssl-1.0.2g/ && tar xvf /usr/local/src/openssl-1.0.2g.tar.gz -C /usr/local/src/openssl-1.0.2g/ --strip-components 1 # ll /usr/local/src/openssl-1.0.2g/
– Ta sẽ tạo 1 file cấu hình custom build mode webserver “nginx_apache” theo ý muốn của quản trị viên.
# mkdir -p /usr/local/directadmin/custombuild/custom/nginx_reverse/ # cp /usr/local/directadmin/custombuild/configure/nginx_reverse/configure.nginx /usr/local/directadmin/custombuild/custom/nginx_reverse/configure.nginx # chown root:root -R /usr/local/directadmin/custombuild/custom/nginx_reverse/ # chmod 755 /usr/local/directadmin/custombuild/custom/nginx_reverse/configure.nginx
– Chỉnh sửa file cấu hình compile mode webserver “nginx_apache” để thêm module OpenSSL 1.0.2, kích hoạt mode HTTP/2 và tắt mode SPDY nếu xuất hiện trong file configure. Do mode SPDY bị Nginx loại bỏ hỗ trợ trong các version mới.
# vi /usr/local/directadmin/custombuild/custom/nginx_reverse/configure.nginx #!/bin/sh ./configure \ "--user=nginx" \ "--group=nginx" \ "--prefix=/usr" \ "--sbin-path=/usr/sbin" \ "--conf-path=/etc/nginx/nginx.conf" \ "--pid-path=/var/run/nginx.pid" \ "--http-log-path=/var/log/nginx/access_log" \ "--error-log-path=/var/log/nginx/error_log" \ "--with-ipv6" \ "--without-mail_imap_module" \ "--without-mail_smtp_module" \ "--with-http_ssl_module" \ "--with-http_realip_module" \ "--with-http_stub_status_module" \ "--with-http_gzip_static_module" \ "--with-http_dav_module" \ "--with-http_v2_module" \ "--with-cc-opt='-D FD_SETSIZE=32768'" \ "--with-openssl=/usr/local/src/openssl-1.0.2g"
3. Chạy rebuild lại hệ thống để cài đặt Nginx version 1.9.11 mainline
– Kiểm tra xem Direct Admin đã nhận file configure custom nginx_reverse làm file cấu hình compile chính hay chưa.
# cd /usr/local/directadmin/custombuild/ # ./build used_configs Nginx (reverse proxy) configuration file: /usr/local/directadmin/custombuild/custom/nginx_reverse/configure.nginx
– Tiến hành rebuild lại Web Server Nginx.
# ./build_nginx-custom
– Bạn đợi 1 khoảng thời gian để hệ thống tiến hành rebuild lại.
– Sau đó kiểm tra xem nginx đã lên version 1.9.11 và có module HTTP/2 hay chưa.
# nginx -V nginx version: nginx/1.9.11 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) built with OpenSSL 1.0.2g 1 Mar 2016 TLS SNI support enabled configure arguments: --user=nginx --group=nginx --prefix=/usr --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --http-log-path=/var/log/nginx/access_log --error-log-path=/var/log/nginx/error_log --with-ipv6 --without-mail_imap_module --without-mail_smtp_module --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_dav_module --with-http_v2_module --with-cc-opt=''-D FD_SETSIZE=32768'' --with-openssl=/usr/local/src/openssl-1.0.2g
Như vậy ta đã hoàn thành việc update phiên bản Nginx trên hệ thống Direct Admin có thể hỗ trợ chức năng giao thức HTTP/2.
Chúc các bạn thành công.