隨着web的發展,開發者對傳輸過程當中的信息安全也應該更爲重視。https
能夠經過ssl
協議來保證信息傳輸過程當中的數據安全,成爲了一些敏感操做的必備選擇。php
https
超文本傳輸安全協議(英語:Hypertext Transfer Protocol Secure,縮寫:HTTPS,也被稱爲HTTP over TLS,HTTP over SSL或HTTP Secure)是一種網絡安全傳輸協議。在計算機網絡上,HTTPS經由超文本傳輸協議進行通訊,但利用SSL/TLS來對數據包進行加密。HTTPS開發的主要目的,是提供對網絡服務器的身份認證,保護交換數據的隱私與完整性。(來源:維基百科)html
https
證書的獲取因爲可信的證書頒發機構只有那麼幾家,因此必需要從他們那裏獲取或者購買。個人https
證書是從騰訊雲那裏免費獲取的,畢竟剛畢業沒錢(網址:https://console.qcloud.com/ssl)。經過以後下載下來就能夠了。nginx
nginx
上啓用https
server { listen 443 ssl; server_name www.****.com;#域名 ssl_certificate ssl_certs/1_www.****.com_cert.crt;#證書路徑 ssl_certificate_key ssl_certs/2_www.****.com.key;#key路徑 ssl_session_cache shared:SSL:1m; #s儲存SSL會話的緩存類型和大小 ssl_session_timeout 5m; #會話過時時間 ssl_ciphers HIGH:!aNULL:!MD5; #爲創建安全鏈接,服務器所容許的密碼格式列表 ssl_prefer_server_ciphers on; #依賴SSLv3和TLSv1協議的服務器密碼將優先於客戶端密碼 location / { root /var/www/; index index.html index.htm index.php; } location ~ \.php$ { root /var/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
http
訪問自動跳轉到https
server{ listen 80 www.****.com; rewrite ^/(.*)$ https://www.****.com/$1 permanent; }