Tomcat9配置HTTP2

HTTP 2.0即超文本傳輸協議 2.0,是下一代HTTP協議。是由互聯網工程任務組(IETF)的Hypertext Transfer Protocol Bis (httpbis)工作小組進行開發。是自1999年http1.1發佈後的首個更新。


系統環境:

CentOS release 6.5 (Final)  x64

JDK 1.8.0_92

apache-tomcat-9.0.0.M6.tar.gz

apr-1.5.2.tar.gz

apr-util-1.5.4.tar.gz

openssl-1.0.2h.tar.gz


本人在安裝的過程中,碰到了很多坑,尤其是需要注意的是,編譯安裝tomcat-native的時候,需要指定openssl,而編譯安裝openssl的時候,需要指定shared

操作步驟如下

一:安裝apr

tar -xvf apr-1.5.2.tar.gz

cd apr-1.5.2

./configure --prefix=/usr/local/apr

make

make install


二:安裝apr-util

tar -xvf apr-util-1.5.4.tar.gz

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make

make install


三:安裝openssl

tar -xvf openssl-1.0.2h.tar.gz

cd openssl-1.0.2h

./config shared --prefix=/usr/local/openssl-1.0.2h

make depend

make

make install

注意這裏必須指定shared


四:安裝

tar -xvf apache-tomcat-9.0.0.M6.tar.gz

cd apache-tomcat-9.0.0.M6/bin

tar -xvf tomcat-native.tar.gz

cd tomcat-native-1.2.7-src/native

./configure --prefix=/usr/local/tomcat-native --with-apr=/usr/local/apr --with-java-home=/usr/local/jdk1.8.0_92 --with-ssl=/usr/local/openssl-1.0.2h

make

make install

注意這裏的--with-ssl 必須指定


五:配置ld

vim /etc/profile

export LD_LIBRARY_PATH=/usr/local/tomcat-native/lib:$LD_LIBRARY_PATH

source /etc/profile


六:生成證書

cd apache-tomcat-9.0.0.M6

mkdir ssl

cd ssl

openssl genrsa -out server.key 2048  

openssl rsa -in server.key -out server.key  

openssl req -new -x509 -key server.key -out ca.crt -days 3650 


七:配置tomcat

cd apache-tomcat-9.0.0.M6/conf

vim server.xml

找到如下內容



把這一段內容,取消註釋

並改成如下內容



保存退出,啓動tomcat


最後,訪問https://192.168.1.200:8443

注意,需要使用https

查看tomcat的訪問日誌

[root@localhost logs]# cat localhost_access_log.2016-06-07.txt 
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET / HTTP/2.0" 200 11234
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /tomcat.css HTTP/2.0" 200 5576
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /tomcat.png HTTP/2.0" 200 5103
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /bg-nav.png HTTP/2.0" 200 1401
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /bg-middle.png HTTP/2.0" 200 1918
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /bg-button.png HTTP/2.0" 200 713
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /asf-logo.png HTTP/2.0" 200 17811
192.168.1.95 - - [07/Jun/2016:12:04:56 +0800] "GET /bg-upper.png HTTP/2.0" 200 3103
192.168.1.95 - - [07/Jun/2016:12:04:57 +0800] "GET /favicon.ico HTTP/2.0" 200 21630

發現,HTTP/2 已經生效了。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章