如何在 apache2 上面啟用 http/2 on CentOS7

CentOS 的 repo 某些套件更新相當的保守
例如 apachephp 就是很實在的例子
目前我使用的 CentOS7 是
印象中 apache 的版本在 CentOS7 上始終停留在 2.4.6

由於 apache 支援的 http/2 功能在 2.4.17 才會出現
(不過 2.4.26 版本不安全,請升級到後續的版本)
所以要先想辦法將 apache 升級
如果不想自己 compile 的話
可以參考這篇的做法

1. 先查詢 apache 的版本
可以用 httpd -v 或是 yum info httpd 查詢

2. 先確認是否安裝 epel-release
$ sudo yum install -y epel-release

3. 下載並安裝 CodeIT repo
$ cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo

4. 使用 yum info httpd 查詢是否可抓到目前最新版的 httpd

5. 如果還沒安裝 apache 可以輸入
$ yum install httpd

6. 如果要升級 apache 的話
$ yum update httpd-*

7. 重啟 apache
$ systemctl restart httpd

接下來要設定讓 site 支援 http/2

1. 要把下面這行
Protocols h2 http/1.1

2. 加入 ssl.conf 或是 httpd.conf
< VirtualHost *:443 >
Protocols h2 http/1.1
  ServerAdmin you@your-awesome-site.com
  ServerName your-awesome-site.com
< /VirtualHost >

3. 重啟 apache
$ systemctl restart httpd

如果想要測試可以用 chrome 的 debug 工具測試
或是利用線上的工具測試


後記:
啟用後 Lumen 上遇到的問題不少
我使用 JWT 認證
token 的部分會被吃掉
間接造成 400 An error while decoding toke 的問題
後來還是降級回 2.4.6 了



參考文章:
How to Install The Latest Apache Server (httpd) on Centos 7
How to enable HTTP/2 support in Apache


Comments

Popular posts from this blog

CentOS7 如何新增/移除 Rich Rule for firewalld

mac 安裝 mtr

Howto use Postman test Cors