提示:
源码安装Nginx时必须使用–with-http_ssl_module参数,启用加密模块,对于需要进行SSL加密处理的站点添加ssl相关指令(设置网站需要的私钥和证书)
1)生成私钥与证书
[root@proxy ~]# cd /usr/local/nginx/conf
//生成私钥
[root@proxy ~]# openssl genrsa > cert.key
//生成证书
[root@proxy ~]# openssl req -new -x509 -key cert.key > cert.pem
2)修改Nginx配置文件,设置加密网站的虚拟主机
[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
… …
server {
listen 443 ssl;
server_name localhost;
#这里是证书文件
ssl_certificate cert.pem;
#这里是私钥文件
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
3)重启nginx服务
[root@proxy ~]# /usr/local/nginx/sbin/nginx -s reload
4)客户端验证
浏览器浏览器访问可验证
[root@client ~]# firefox https://www.c.com
结束语:
更多精彩内容持续更新中,关注微信公众号,有你更精彩。