NHANWEB

Enable Mod_HTTP2 cho Apache sử dụng CWP sử dụng SSH

Okie, nếu bạn sử dụng dịch vụ cloudflare thì hiển nhiên HTTP/2 được hỗ trợ theo mặc định. Tuy nhiên đấy chỉ là phần từ dịch vụ CloudFlare(CF) đến máy máy client thôi. Còn phần từ CF đến máy chủ của mình thì vẫn chạy HTTP/1 do đó giảm đáng kể về hiệu suất và hiệu quả cũng như tốc độ của HTTP/2.

Trong bài này chúng ta sẽ cùng giải quyết bài toán cài đặt và bật HTTP/2 lên trên máy chủ CWP của mình để bài toán được giải quyết từ gốc đến ngọn.

Lọi ích của HTTP/2

Phần lợi ích của protocol HTTP/2 mình không cần phải nói nữa, các bạn chịu khó đọc trên Internet nhé. Có rất nhiều link chia sẻ chi tiết về lịch sử, lý do tại sao HTTP/2 ra đời và những lợi ích của nó so với HTTP/1 là gì. Các bạn tự research và tìm hiểu.

Enable Mod_HTTP2 cho Apache sử dụng CWP

Upgrade Openssl

Đầu tiên cần nâng cấp Openssl lên cái đã:

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz
tar zxvf openssl-1.1.0h.tar.gz
cd openssl-1.1.0h
./config --prefix=/usr --openssldir=/usr/lib64 shared
make
make install

Upgrade Autoconf

cd /usr/local/src
wget https://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-*
./configure --prefix=/usr
make
make install

UInstall Nghttp2

cd /usr/local/src
yum install libtool libuuid-devel libuuid -y
git clone https://github.com/nghttp2/nghttp2.git
cd nghttp2
autoreconf -i
automake
autoconf
./configure --prefix=/usr
make
make install

Install APR (nếu cần)

cd /usr/local/src
rm -rf apr*
wget https://archive.apache.org/dist/apr/apr-1.6.5.tar.gz
wget https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
tar -xf apr-1.6.5.tar.gz
tar -xf apr-util-1.6.1.tar.gz
cd /usr/local/src/apr-1.6.5
./configure --prefix=/usr/local/apr1
make
make install
cd /usr/local/src/apr-util-1.6.1
./configure --with-apr=/usr/local/apr1 --prefix=/usr/local/apr-util1
make
make install

Rebuilding Apache với http2

Việc tiếp theo là phải rebuild lại Apache để load thêm module http2 mới cài đặt vào. Việc này có thể làm thông qua giao diện GUI của CPW. Một cách nhanh chóng thì nó được thực hiện như sau:

  1. Backup file httpd.conf
  2. Truy cập Apache Settings -> Apache Re-build
  3. Chọn Select NEW Apache version: và click Next
  4. Bổ sung –-enable-http2 vào danh sách Additional configuration
  5. Click Start Compiler và ngồi đợi cho đến khi có thông báo. Việc re-build được thực hiện dưới nền nên bạn có thể rảnh tay đi làm việc khác

Hoặc một cách khác là bạn có thể xóa hết Additional configuration ./configure –enable-so –prefix=/usr/local/apache –enable-unique-id –enable-ssl=/usr/local/opensslso –enable-rewrite –enable-deflate –enable-suexec –with-suexec-docroot=”/home” –with-suexec-caller=”nobody” –with-suexec-logfile=”/usr/local/apache/logs/suexec_log” –enable-asis –enable-filter –with-pcre –with-apr=/usr/local/apr1/bin/apr-1-config –with-apr-util=/usr/local/apr-util1/bin/apu-1-config –enable-headers –enable-expires –enable-proxy –enable-rewrite –enable-userdir –enable-http2

Enable Mod_http2 Module

Sau khi hoàn tất việc rebuild lại Apache, bạn mở file /usr/local/apache/conf.d/http2.conf và thêm vào đoạn sau:

LogLevel http2:info
Protocols h2 h2c http/1.1

hoặc là:

LoadModule http2_module modules/mod_http2.so

LogLevel http2:info
Protocols h2 h2c http/1.1

sau đó chúng ta restart lại Apache

service httpd restart

Công cụ kiểm tra và xác nhận

Nhanweb HTTP2

Một vài công cụ kiểm tra Online có thể giúp bạn xem thửu website mình đã có hỗ trợ HTTP/2 hay chưa như:

Tuy nhiên như đã nói ở trên, việc kiểm tra này sẽ không có giá trị nếu như bạn sử dụng một dịch vụ như Cloudflare. Để kiểm tra bạn có thể active module server-status lên. Hoặc đơn giản hơn là tắt proxy của Cloudflare đi mới kiểm tra chính xác được.

Exit mobile version