[TOC]
1 說明
此處介紹在CentOS6.8系統(tǒng)上茧彤,使用openSSL建立私有CA电爹,并頒發(fā)證書锚烦,以配置 nginx 支持https砚著。
2 創(chuàng)建私有CA(私有CA生成自簽署的證書)
這部分的相關(guān)內(nèi)容請看本人的另一篇文章
http://blog.csdn.net/hylexus/article/details/53058135
http://www.reibang.com/p/7ad4846a2f38
或者此處用真正互聯(lián)網(wǎng)通用的證書也是一樣的蝴猪。
3 為nginx配置SSL支持
# 此處在ssl目錄下進行操作,位置按自己的需要吧
[root@h1 ssl]# pwd
/etc/nginx/ssl
3.1 生成私鑰
[root@h1 ssl]# (umask 077;openssl genrsa -out nginx.key 1024)
3.2 生成證書頒發(fā)請求
# 按要求填寫相關(guān)信息即可
[root@h1 ssl]# openssl req -new -key nginx.key -out nginx.csr
3.3 頒發(fā)證書
此處使用私有CA頒發(fā)走敌,并且本人的CA和httpd在同一臺主機上统求。
# 由于此處CA和httpd在同一臺主機上害淤,所有直接將頒發(fā)的證書放置到了/etc/nginx/ssl/nginx.crt目錄
[root@h1 ssl]# openssl ca -in /etc/nginx/ssl/nginx.csr -out /etc/nginx/ssl/nginx.crt -days 365
3.4 nginx 配置
未啟用https前的虛擬主機簡單配置如下:
server{
listen 80;
server_name h3.hylexus.tech;
access_log /logs/aaa.access.log;
location /{
index index.html;
root /web/html/h3.hylexus.tech;
}
}
注意修改hosts文件,將域名加進去
[root@h1 conf.d]# cat /etc/hosts
# ………………
127.0.0.1 localhost.localdomain localhost h3.hylexus.tech
192.168.161.128 h1 h3.hylexus.tech
# ………………
先確保使用http協(xié)議能訪問的虛擬主機之后再繼續(xù)下文熊镣。
先用http協(xié)議訪問 http://h3.hylexus.tech試試卑雁。成功后繼續(xù)下文。
啟用HTTPS
server{
# 同時支持http和https
listen 80;
listen 443 ssl;
server_name h3.hylexus.tech;
access_log /logs/aaa.access.log;
keepalive_timeout 70;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
location /{
index index.html;
root /web/html/h3.hylexus.tech;
}
}
3.5 訪問
記得修改hosts文件绪囱,因為這個域名純粹是瞎編的……
當(dāng)然瀏覽器會告警說證書來源不可信之類的测蹲,不告警才怪呢……除非你的證書是互聯(lián)網(wǎng)通用的而不像我們這里自己給自己頒發(fā)的……