nginx下如何配置 ssl證書?騰訊雲ssl證書為例!
目前為止,https已經成為一種趨勢,想要開啟https就需要ssl證書。
首先,為域名注冊ssl證書。
騰訊雲注冊地址:https://cloud.tencent.com/product/ssl?from=qcloudHpHeaderSsl
(騰訊雲這里有免費的個人證書,一次性一年)
接下來怎么配置到nginx呢?
假設我們的網站域名是adcc.me,php環境采用的是phpstudy一鍵安裝的。
/phpstudy/server/nginx/conf/vhosts 目錄下的 adcc.me.conf 文件配置如下:
server { listen 443; server_name adcc.me; root "/phpstudy/www/adcc.me"; ssl on; ssl_certificate /phpstudy/server/nginx/conf/1_adcc.me_bundle.crt; #ssl證書存放路徑 ssl_certificate_key /phpstudy/server/nginx/conf/2_adcc.me.key; #ssl證書存放路徑 ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照這個協議配置 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照這個套件配置 ssl_prefer_server_ciphers on; location / { index index.html index.htm index.php; #autoindex on; } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root; include fastcgi_params; } }
(注意ssl證書上傳的路徑)
修改好adcc.me.conf文件之后。通過xshell5 登錄服務器,輸入phpstudy restart 命令,重啟nginx即可。
接下來在/phpstudy/www/adcc.me 路徑下放一個index.html的網頁,使用https://adcc.me測試訪問下,如果能訪問就說明ssl證書已經配置成功。
關於phpstudy 的使用說明,請參照:http://www.cnblogs.com/hylsay/p/7782738.html
原文參考:https://adcc.me