nginx实现https

实现Nginx的https
1、申请证书,这里申请腾讯云的证书
1)登录腾讯云控制台,依次单击“云产品”>“SSL证书管理”>“申请证书”
2)在免费证书申请页面填写相关信息,如下
这里写图片描述
3)单击“下一步”,在域名身份验证页面单击“确认申请”
注:由于xxx.com这个主域名不是该账号下或腾讯云下的域名,需要做手动DNS验证
4)切换到SSL证书管理控制台,在证书列表下找到目标证书(即刚才申请的证书),然后单击目标证书右侧的“详情”
这里写图片描述
5)按照上图的提示,在主域名那里添加相关的CNAME记录,用来做手动DNS验证,如下操作
这里写图片描述
6)切换到目标证书详情,单击“下载”,把证书下载到本地

7)在下载的证书里面,包含如下三个目录,在这里只需要用到nginx的目录

2、配置nginx
1)安装nginx,这里过程省略
2)启动nginx
[root@nginx ~]# /usr/local/nginx/sbin/nginx
[root@nginx ~]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4492/nginx: master
3)修改nginx.conf文件,添加如下内容
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 443; #SSL访问端口号
server_name test01.xxx.com; #填写绑定证书的域名
ssl on; #启用SSL功能
ssl_certificate 1_test01.xxx.com_bundle.crt; #指定证书文件
ssl_certificate_key 2_test01.xxx.com.key; #指定证书私钥文件
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用的协议
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #配置加密套件,写法遵循openssl标准
ssl_prefer_server_ciphers on;
location / {
root html; #站点目录
index index.html index.htm;
}
}
4)将相关证书文件和私钥文件上传到/usr/local/nginx/conf/
[root@nginx ~]# cd /usr/local/nginx/conf/
[root@nginx conf]# ls test01
1_test01.xxx.com_bundle.crt
2_test01xxx.com.key
5)添加相关测试页
[root@nginx ~]# echo “this nginx https” > /usr/local/nginx/html/index.html
6)重载nginx
[root@nginx ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# /usr/local/nginx/sbin/nginx -s reload
[root@nginx ~]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 739/nginx: master p
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 739/nginx: master p
3、在主域名中添加相关A记录
1)切换到主域名控制台,单击“解析”

2)单击“添加记录”

3)添加如下信息
这里写图片描述
注:“183.61.xx.xx”是nginx服务器地址
4、在浏览器上登录验证
这里写图片描述

转载于:https://my.oschina.net/u/3551412/blog/979257

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值