天天看點

nginx下如何配置 ssl證書?騰訊雲ssl證書為例!

nginx下如何配置 ssl證書?騰訊雲ssl證書為例!
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