## 了解http2協議
1. HTTP 2.0 的主要目標是改進傳輸性能,實現低延遲和高吞吐量。從另一方面看,HTTP 的高層協議語義并不會因為這次版本升級而受影響。 **所有HTTP 首部、值,以及它們的使用場景都不會變**。
2. 現有的任何網站和應用,無需做任何修改都可以在HTTP 2.0 上跑起來。不用為了利用HTTP 2.0 的好處而修改標記。HTTP 服務器必須運行HTTP 2.0 協議,但大部分用戶都不會因此而受到影響
。
## 編譯nginx的http2模塊
通過 `/usr/local/nginx/sbin/nginx -V
` (注意是大寫的V),查看當前nginx是否支持http2:**--with-http_v2_module**
```
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2o 27 Mar 2018
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/usr/local/src/lnmp1.5/src/openssl-1.0.2o
```
如果沒有的話在編譯nginx時要加上這一行
```
./configure \
--user=www \
--group=www \
--with-http_v2_module \
--with-http_ssl_module \
--with-stream \
--with-openssl=./openssl-OpenSSL_1_1_0e \
--with-pcre=./pcre-8.40 --with-pcre-jit \
--with-zlib=./zlib-1.2.11
make && make install
```
## 生成證書
可以參考我上一篇博文,申請免費證書。也可以手動生成一個偽證書
```
cd /usr/local/nginx/conf/
mkdir key && cd key
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
(根據提示隨意的輸入)
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
```
最終生成
```
[root@zhouzhou_01 key]# ll
總用量 8
-rw-r--r-- 1 root samba 0 6月 14 10:41 server.crt
-rw-r--r-- 1 root samba 749 6月 14 10:41 server.csr
-rw-r--r-- 1 root samba 963 6月 14 10:39 server.key
```
## 配置nginx
主要配置段如下
```
server {
listen 80;
server_name site.com www.site.com;
add_header Strict-Transport-Security max-age=31536000;
return 301 https://www.site.com$request_uri;
}
server {
listen 443 ssl http2;
server_name www.site.com;
root /var/www/html/site;
index index.php index.html index.htm;
access_log /var/log/dnmp/nginx.site.access.log main;
error_log /var/log/dnmp/nginx.site.error.log warn;
ssl on;
ssl_certificate /etc/nginx/conf.d/certs/site/www.site.com.crt;
ssl_certificate_key /etc/nginx/conf.d/certs/site/www.site.com.key;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
add_header Strict-Transport-Security max-age=31536000;
}
```
## 驗證
- 使用Chrome訪問啟用http2的站點。
- 新開TAB頁,在地址欄中輸入chrome://net-internals/#http2,檢查HTTP/2 sessions下的表格。
- 確認表格里是否出現了上一步訪問的主機地址。
- Apache
- 【Apache運維基礎(1)】Apache的安裝與使用
- 【Apache運維基礎(2)】主配置文件說明
- 【Apache運維基礎(3)】虛擬主機配置說明
- 【Apache運維基礎(4)】Apache的Rewrite攻略(1)
- 【Apache運維基礎(5)】Apache的Rewrite攻略(2).htaccess文件
- 【Apache運維基礎(6)】Apache的日志管理與分析
- 工具篇
- supervisor進程管理器
- Haproxy安裝與配置
- Nginx
- 【nginx網站性能優化篇(1)】gzip壓縮與expire瀏覽器緩存
- 【nginx網站性能優化篇(2)】反向代理實現Apache與Nginx的動靜分離(LNMPA)
- 【nginx網站性能優化篇(3)】反向代理實現負載均衡
- 【nginx網站性能優化篇(4)】理解nginx的高并發原理及其配置調優
- 【nginx運維基礎(1)】Nginx的編譯安裝與使用
- 【nginx運維基礎(2)】Nginx的配置文件說明及虛擬主機配置示例
- 【nginx運維基礎(3)】Nginx的編譯PHP
- 【nginx運維基礎(4)】Nginx的日志管理(日志格式與定時分割日志)
- 【nginx運維基礎(5)】Nginx的location攻略
- 【nginx運維基礎(6)】Nginx的Rewrite語法詳解
- 【nginx運維基礎(7)】配置SSL支持https訪問
- 【nginx運維基礎(8)】配置支持http2協議
- 【nginx運維基礎(9)】了解PHP-FPM 與 Nginx 的通信機制
- 其它
- Apache與Nginx下php隱藏http頭部版本信息的實現方法
- CURL與PHP-CLI的應用【CLI篇】
- CURL與PHP-CLI的應用【Curl篇】
- Linux之SAMBA共享服務
- 【Linux常識篇(1)】所謂的正向代理與反向代理
- 【Linux常識篇(2)】理解inode
- 【Linux常識篇(3)】文件及文件夾的ctime atime mtime的含義詳解
- centOS使用手記
- 服務器日志分析
- 高頻命令
- df
- mv
- gzip
- cp
- tar
- touch
- cat
- uniq
- nl
- more
- rmdir
- less
- mkdir
- head
- rm
- tail
- 五大查詢命令
- vi&vim
- ls與目錄結構
- grep
- awk
- sed
- 其他高頻命令