https 須要購買域名ssl證書javascript
注意事項:php
1.要開啓HTTP/2協議支持,須要在nginx 1.10以上版本而且須要openssl庫的版本在1.0.2及以上編譯。css
2.http2.0只支持開啓了https的網站。html
openssl version 能夠查看openssl版本java
nginx -v 能夠查看nginx版本node
mysql -v 能夠查看mysql版本mysql
php -v 能夠查看php版本linux
如下命令能夠查看linux版本nginx
uname -a;sql
more /etc/issue;
cat /proc/version;
開始:
這裏個人證書是使用阿里雲提供的免費證書
1.下載證書
2.安裝證書
# HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # # #} #}
server { listen 443; server_name localhost; ssl on; root html; index index.html index.htm; ssl_certificate cert/1533488566332.pem; ssl_certificate_key cert/1533488566332.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } }
保存退出。
問題:可是安裝後 執行 systemctl start nginx 報錯 the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf
原來是nginx安裝時候沒有加載 ssl模塊 和 http2模塊
1)切換到nginx源碼包
user nginx nginx; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 8; gzip_vary on; gzip_types text/plain application/x-javascript text/css text/json application/xml text/javascript application/javascript; gzip_disable "MSIE"; server_tokens off; # sendfile on; #tcp_nopush on; #keepalive_timeout 0; # keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; root /data; #charset koi8-r; #access_log logs/host.access.log main; location / { root /data; index index.php index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /data; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /data; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } server { listen 80; server_name www.fibst.cn; return 301 https://$server_name$request_uri; } server{ #listen 80; listen 443 ssl http2; server_name www.fibst.cn; ssl on; ssl_certificate cert/www.fibst.cn.pem; ssl_certificate_key cert/www.fibst.cn.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; root /data/suxiaoying/; index index.html index.htm index.php; location ~ ^(.*)\/\.svn\/ { return 404; } location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }