Linux:使用ssl加密网站为https

本文详细描述了如何在Linux服务器上使用OpenSSL创建SSL证书和私钥,为网站设置HTTPS,包括配置Nginx虚拟主机以支持安全连接,并通过实例演示了整个过程。
摘要由CSDN通过智能技术生成

Linux:使用ssl加密网站为https

生成对应的数字证书以及密钥

[root@server100 ~]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/nginx/certs/timinglee.org.key -x509 -days 365 -out /etc/nginx/certs/timinglee.org.crt

......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.......+.+......+..+......+......+.+..+.+............+...+...........+...+............+.+.....+...+..........+.........+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+....+........................+.........+.....+......+.......+.........+.....+...+..........+....................+.+..+...............+....+...+...+...+....................+.+.....+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
..+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*............+................+...+.........+..+...+.......+.....+.+..+.+..+..........+.........+......+.....+...+......+...+.+...........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.......+.....+.......+...+..............+......+........................+...+...............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
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) [XX]:china
String too long, must be at most 2 bytes long
Country Name (2 letter code) [XX]:shannxi
String too long, must be at most 2 bytes long
Country Name (2 letter code) [XX]:86
State or Province Name (full name) []:shannxi
Locality Name (eg, city) [Default City]:xian
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:RHCE
Common Name (eg, your name or your server's hostname) []:shanxin
Email Address []:123@alis.com

[root@server100 ~]# cat /etc/nginx/certs/timinglee.org.key

[root@server100 ~]# cat /etc/nginx/certs/timinglee.org.crt

配置虚拟主机基于https访问

[root@server100 ~]# vim /etc/nginx/conf.d/vhosts.conf

server{
        listen 443 ssl;
        server_name login.timinglee.org;
        ssl_certificate "/etc/nginx/certs/timinglee.org.crt";
        ssl_certificate_key "/etc/nginx/certs/timinglee.org.key";
        root /usr/share/nginx/virtual/login;
        index index.html;
}

[root@server100 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server100 ~]# systemctl restart nginx.service
[root@server100 ~]# mkdir -p /usr/share/nginx/virtual/login
[root@server100 ~]# echo 'login.timinglee.org' > /usr/share/nginx/virtual/login/index.html

使用firefox浏览器测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值