。php
經過 `/usr/local/nginx/sbin/nginx -V
` (注意是大寫的V),查看當前nginx是否支持http2:--with-http_v2_modulehtml
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時要加上這一行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
能夠參考我上一篇博文,申請免費證書。也能夠手動生成一個僞證書chrome
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
主要配置段以下session
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; }