3个步骤:
- 注册阿里云账号,然后在阿里云上申请一个SSL证书
- 安装 nginx Web服务器
- 配置SSL证书,使网站支持https安全访问
1. 注册阿里云账号,然后在阿里云上申请一个SSL证书
注册阿里云账号并登陆
进入SSL证书:

立即购买:

选择免费证书:

支付:

确认支付:

支付成功,进入控制台:

申请证书,需要输入域名,因为证书是和域名绑定的,免费的只能支持单域名:

填写证书信息,选择手动DNS验证

记住 记录类型,主机记录,记录值,然后添加到域名解析里

域名解析里添加一个TXT解析,然后确定:

到此SSL证书就申请完成了,完成后就等待CA中心认证,一般当天就可以验证成功
2. 安装 nginx Web服务器
官网安装说明地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS
新建文件:/etc/yum.repos.d/nginx.repo
保存文件内容:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
说明如图:

文件保存后输入下面的命令安装nginx,这样就可以安装最新版的nginx
yum install nginx
提示安装输入: y,如图

更新秘钥输入:y,如图
安装完成 !
可以执行如下操作
systemctl start nginx.service #启动nginx服务
systemctl stop nginx.service #关闭nginx服务
systemctl restart nginx.service #重启nginx服务
systemctl status nginx.service #查看nginx服务运行状态
启动nginx后,查看nginx端口监听
systemctl start nginx.service
netstat -tnlp
监听了80端口,如图:

3. 配置SSL证书,使网站支持https安全访问
如果第2个步骤证书申请通过了,需要我们下载证书,如图:

下载证书:

下载后压缩包里有两个文件:一个是pem文件,一个是key文件,放到服务器上指定目录,假如我放到 /opt/cert/下,如图:

打开nginx配置文件:/etc/nginx/conf.d/default.conf
清空原来所有内容,输入新的内容如下:
server {
listen 443;
server_name www.yourdomain.com; #你的申请过证书的域名
client_max_body_size 64M;
fastcgi_read_timeout 3600;
error_page 500 502 503 504 /50x.html;
root /usr/share/nginx/html;
try_files $uri $uri/ @rewrite;
ssl on;
ssl_certificate /etc/nginx/cert/www.yourdomain.com.pem; # 证书pem文件,根据自己证书的所在位置
ssl_certificate_key /etc/nginx/cert/www.yourdomain.com.key; # 证书key文件,根据自己证书的所在位置
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
ssl_prefer_server_ciphers on;
}
这里要注意三个地方
- 你的申请过证书的域名
- 证书pem文件,根据自己证书的所在位置和名称
- 证书key文件,根据自己证书的所在位置和名称
配置完成后重启nginx服务:
systemctl restart nginx.service
最后解析你需要访问的域名

等待域名解析生效后,就可以通过https和域名访问自己的网站了,如图:

网友评论