做者簡介:php
姓名:黃志成(小黃)博客: 博客html
今天須要給域名加上https,特來記錄一下.整體來講很簡單~沒有什麼坑nginx
這裏咱們使用的是 阿里雲的免費CA證書服務.web
購買地址 : CA證書購買地址api
購買完以後,進入CA證書管理後臺.安全
補全你的我的信息,而後在選擇認證方式 這裏有兩種方式 服務器
域名解析 和 文件判斷 .這裏就不作太多說明了. 我選的是域名解析.session
key生成方式,我也是選擇的由阿里雲生成.阿里雲
等待他們審覈完成(這裏是自動審覈的).spa
這個時候 咱們下載證書,上傳到服務器便可. 放在 nginx的 confing/cert目錄下
![image](http://img.webhuang.cn/nginx_...
)
這裏把個人nginx的配置項發到這裏.
server { listen 443; server_name www.webhuang.cn; client_max_body_size 10m; set $root_path '/home/huangzhicheng/wwwroot/api/public/'; root $root_path; ssl on; ssl_certificate cert/214583152630280.pem; ssl_certificate_key cert/214583152630280.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; access_log /data/logs/nginx/$host-access.log main; error_log /data/logs/nginx/$host-error.log error; index index.php index.html index.htm; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } location ~ \.php { root $root_path; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ /\.ht { deny all; } }
這裏的配置項根據你實際狀況來更改.
配置完成後,檢查一下nginx配置文件是否可用,有successful表示可用。
nginx -t // 檢查nginx配置文件
配置正確後,從新加載配置文件使配置生效:
nginx -s reload // 使配置生效
這裏還有個小坑.在這裏我列出來.
1.若是使用的是 阿里雲的服務器 須要在安全組中修改端口過濾規則把443端口開放才能訪問到.
2.須要查看是否有防火牆。
如何打開 443 端口防火牆呢? : 參考連接 (這裏是Centos7的方法)
好啦。待會下班了.今天也是清明假期後的第一天上班.