[box style=”info”] 服务器环境: VPS类型:OpenVZ(oneasiahost) 操作系统:debian 6.0 服务器环境:军哥LNMP环境 配置:1核/128M/10G [/box]
上面我说过,换了IP之后需要申请重发证书,重发证书的时候首先要在服务器上面生成两个文件一个是key(密钥文件)文件,一个是csr(证书请求文件)文件。
首先生成key文件:
root@lianst:~#cd /usr/local/nginx/conf/
root@lianst:/usr/local/nginx/conf# openssl genrsa -out www.lianst.cn.key 2048
再来生成csr文件:
root@lianst:/usr/local/nginx/conf# openssl req -new -key www.lianst.cn.key -out www.lianst.cn.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [AU]:CN (这里输入两位大写字母的国家代码 CN是中国)
State or Province Name (full name) [Some-State]:JiangSu (这里省份 可以填写简称,一般填写拼音)
Locality Name (eg, city) []:SuZhou (这里是城市可以填写简称,一般填拼音)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:LianShiTong (组织或公司名)
Organizational Unit Name (eg, section) []: (不填写直接回车)
Common Name (eg, YOUR name) []:www.lianst.cn (输入使用ssl的域名,一般不带www)
Email Address []:lianshitong@gmail.com(填写邮箱,有时候证书是发送到这个邮箱)
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: (不填写直接回车)
An optional company name []: (不填写直接回车)
完成之后将csr(证书请求文件)发给你的证书申请机构(我的证书是在淘宝上面买的,所以我就直接发给淘宝店主就好了),然后你会接到一封邮件让你确认。过一会(时间不一定)会接到证书机构发来的邮件,里面有一个压缩包,解压出来有三个文件。
首先,我们要来把这三个文件进行合并(注意合并的时候是有顺序的)。在这里,我新建了一个ssl.csr文件,依次将www_lianst_com.crt、PositiveSSLCA2.crt、AddTrustExternalCARoot.crt的内容复制到新建的ssl.csr文件里面。合并完成之后将ssl.csr和www.lianst.cn.key上传到/usr/local/nginx/conf/下面,之后修改nginx.conf文件开启ssl支持。插入以下内容到server{}的后面:
server
{
listen 443;
server_name www.lianst.cn lianst.com;
index index.html index.htm index.php;
root /home/wwwroot/lianst.com;
ssl on;
ssl_certificate ssl.crt;
ssl_certificate_key www.lianst.cn.key;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param HTTPS on;
include fcgi.conf;
}
然后保存,重启Nginx,如果没有报错的话,那么恭喜你,你已经顺利的启用了SSL。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有