目前網站SSL證書基本已經普及了,很多站點基本都安裝了SSL證書,而且目前不管是國內比較知名的雲商家基本都提供免費的SSL證書。本次說的是阿里雲提供的免費ssl證書。
廢話不多說,直接上步驟:
1、登錄阿里雲控制台:https://www.aliyun.com/,點開產品服務->安全(雲盾)->SSL證書(應用安全),如圖:
2、進入之后點擊右上角“購買證書”
3、選擇品牌“Symantec”-->選擇保護類型“1個域名”,這時候才會出現證書類型“免費型DV SSL”,選擇這個免費的即可
4、選好之后點擊購買即可
5、付完款之后返回證書控制台
6、點擊申請,按照需求填寫相關信息,然后點下一步,驗證即可。提交審核后稍等幾分鍾就能通過審核了。
證書通過之后,接下來就是配置的事了。這里以nginx為例。
1、下載證書-->選擇需要的服務器類型,這里以nginx為例。
2、下載好之后登陸服務器,打開nginx目錄/usr/local/nginx,新建一個文件夾cert,講證書解壓后放進cert文件夾內。
3、配置nginx
server { listen 443 ssl; #listen 80; server_name www.zhudada.online; ssl_certificate /usr/local/nginx/cert/1631577_zhudada.online.pem; ssl_certificate_key /usr/local/nginx/cert/1631577_zhudada.online.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location ~ .*\.(js|css|ico|png|jpg|gif|mp3|eot|svg|ttf|woff|html) { root /home/zhudada; index index.html; } # location / { # proxy_set_header Host $host; # proxy_pass http://47.107.99.77:80/index.html; # } }
4、重啟nginx即可。
到這里需要注意幾個問題:
1、Nginx如果未開啟SSL模塊,配置Https時提示錯誤。
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx
這是由於nginx缺少http_ssl_module模塊,編譯安裝的時候帶上--with-http_ssl_module配置就行了,解決步驟:
1:進入到源碼包,如:
cd /root/nginx-1.15.6/
2:查看nginx原有的模塊
/usr/local/nginx/sbin/nginx -V
3:查看configure arguments:后邊有沒有值,如果有,就復制下來。然后執行
./configure --原來有的模塊(如果有的話) --with-http_ssl_module
4:執行make
make
5:關閉現在運行的Nginx服務器
/usr/local/nginx/sbin/nginx -s stop
提示:如果此時報錯nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:xxx,則先把有關https的配置注釋再關閉。
6:執行
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
7:將新的 nginx 覆蓋舊安裝目錄,執行
cp objs/nginx /usr/local/nginx/sbin/nginx
8:最后重啟一下nginx即可
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
驗證一下:輸入/usr/local/nginx/sbin/nginx -V,這時會出現下面這種情況,說明已經成功了,可以用https訪問你的網站了:
補充幾點:
1、在上面第3步執行./configure的時候可能會出現以下報錯:
./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.
解決方法:
Centos需要安裝openssl-devel
Ubuntu則需要安裝:sudo apt-get install libssl-dev
這時如果報錯 Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
解決方法:
第一種:
sudo vim /etc/resolv.conf
添加nameserver 8.8.8.8
第二種:
/etc/apt/sources.list 的內容換成
deb http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring main universe restricted multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-security main universe restricted multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-updates main universe restricted multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-backports main restricted universe multiverse
deb http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ raring-proposed main restricted universe multiverse
然后sudo apt-get update一下就行了。
2、nginx配置輸入網址后默認跳轉至https站點
server {
listen 80;
server_name www.zhudada.online;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
#listen 80;
server_name www.zhudada.online;
ssl_certificate /usr/local/nginx/cert/1631577_zhudada.online.pem;
ssl_certificate_key /usr/local/nginx/cert/1631577_zhudada.online.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location ~ .*\.(js|css|ico|png|jpg|gif|mp3|eot|svg|ttf|woff|html) {
root /home/zhudada;
index index.html;
}
# location / {
# proxy_set_header Host $host;
# proxy_pass http://47.107.99.77:80/index.html;
# }
}
到這里就結束了,如果安裝配置過程中有任何問題,可以問我
qq: 412606846(微信同號)