http? https?这一篇就交给你怎么做https网站

前言

路人皆知,https类型网站比http网站安全,https是启用ssl加密的安全HTTP传输协议。现在大部分网站也都是https加密后的。

https实现方式:

SSL: 安全套接字层,由Netscape公司于1994年创建,它旨在通过Web创建安全的Internet通信。它是一种标准协议,用于加密浏览器服务器之间的通信。它允许通过Internet安全轻松地传输账号密码、银行卡、手机号等私密信息。
PKI: 公钥基础设施,主要功能是绑定书持有者的身份和相关的密钥对(通过为公钥及相关的用户身份信息签发数字证书),为用户提供方便的证书申请、证书作废、证书获取、证书状态查询的途径.并利用数字证书及相关的各种服务(证书发布,黑名单发布,时间戳服务等),实现通信中各实体的身份认证、完整性、抗抵赖性和保密性.

CA: 证书颁发机构
RA: 书注册机构

国际顶级CA颁发机构:

赛门铁克是 SSL/TLS 证书的领先提供商,为全球一百多万台网络服务器提供安全防护。该品牌证书由工信部许可设立的电子认证服务机构“天威诚信”提供鉴证服务。
在这里插入图片描述

GeoTrust是全球第二大数字证书颁发机构,已被Symantec收购。该品牌证书由工信部许可设立的电子认证服务机构“天威诚信”提供鉴证服务。
在这里插入图片描述

GMO GlobalSign是全球最早的数字证书认证机构之一,一直致力于网络安全认证及数字证书服务,是一个备受信赖的 CA 和 SSL 数字证书提供商
在这里插入图片描述

中国金融认证中心(CFCA)证书,由中国数字证书认证机构自主研发,纯国产证书。
在这里插入图片描述
HTTPS证书的选择

  • 专业版OV型 不显示企业名
  • 高级版EV型 显示企业名

HTTPS证书购买选择

  • 单域名:仅能绑定一个域名
  • 多域名:能绑定五个域名
  • 通配符域名:不限个数

企业或线上如果需要注册使用ssl证书,阿里云提供了平台就可以选择购买,在购买证书之前,要保证你的域名合法可用,提前把域名审核通过。购买后会生成证书加密文件,具体步骤和下面差不多,就不需要本机当CA颁发证书和其他步骤了,具体可以参考:https://blog.csdn.net/macex002/article/details/81155713

企业内部实现https负载均衡案例

环境:

服务器 用途作用
nginx,php(192.168.10.5) 做web2节点服务器 ,做web2的php服务器
nginx,mysql(192.168.10.6) 做web1节点服务器,做web2的数据库
nginx(192.168.10.2) 做反向代理负载均衡服务器(lb1)
mysql(192.168.10.4) 做web1的数据库
php(192.168.10.3) 做web1的php服务器
nginx(192.168.10.7) 做反向代理负载均衡服务器(lb2)
测试机(192.168.10.1) 测试访问

在web1和web2节点服务器上做好ssl加密

查看是否安装openssl和版本
rpm -q openssl

查看nginx是否安装ssl模块
nginx -V 显示结果包含:--with-http_ssl_module

创建ssl密钥目录,并进入目录

mkdir -p /etc/nginx/ssl_key 
cd /etc/nginx/ssl_key

本机当CA:证书颁发机构,创建私钥

[root@localhost ssl_key]# openssl genrsa -idea -out server.key 2048
Generating RSA private key, 2048 bit long modulus
..........................+++
................+++
e is 65537 (0x10001)
Enter pass phrase for server.key:        #输入2048
Verifying - Enter pass phrase for server.key:   #输入2048
[root@localhost ssl_key]# 
[root@localhost ssl_key]# ls
server.key

生成证书,去掉私钥的密码

[root@localhost ssl_key]# openssl req -days 3650 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
Generating a 2048 bit RSA private key
...+++
................+++
writing new private key to 'server.key'
-----
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]:bj
State or Province Name (full name) []:bj
Locality Name (eg, city) [Default City]:bj
Organization Name (eg, company) [Default Company Ltd]:bj
Organizational Unit Name (eg, section) []:bj
Common Name (eg, your name or your server's hostname) []:bj
Email Address []:[email protected]
[root@localhost ssl_key]# 
[root@localhost ssl_key]# ls
server.crt  server.key

配置web1网站配置文件
编辑blog.benet.com,添加加密项

server {
        listen 443 ssl; #监听443,加密
        server_name blog.benet.com;
        ssl_certificate ssl_key/server.crt;
        ssl_certificate_key ssl_key/server.key;
        root /www/wordpress;
        index index.php index.html;

        location ~ \.php$ {
                root /www/wordpress;
                fastcgi_pass 192.168.10.3:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
                }
        }
server {            #添加此项是为了人们习惯不输入https也可以访问
        listen 80;
        server_name blog.benet.com;
#       rewrite .* https://blog.benet.com;
#       rewrite .* https://$host$request_uri redirect;
#       rewrite .* https://$server_name$request_uri redirect;
        rewrite .* https://$server_name$1 redirect;
}
保存退出
systemctl restart nginx

在web2上相同的操作,scp复制

[root@web2 nginx]# scp root@192.168.10.6:/etc/nginx/conf.d/blog.conf ./conf.d/
别忘了把加密证书文件拷贝过来
[root@web2 nginx]# scp -rp root@192.168.10.6:/etc/nginx/ssl_key ./

修改配置文件,把php服务器换成web2的

fastcgi_pass 192.168.10.3:9000;===>  fastcgi_pass 127.0.0.1:9000;
保存退出
systemctl restart nginx

最后修改lb1的配置文件,因为之前都做过负载均衡,保留的快照

upstream web_cluster {
        server 192.168.10.6:443 weight=1;
        server 192.168.10.5:443 weight=1;
        }
server {
        listen  443 ssl; 监听https,加密
        server_name     blog.benet.com;
        ssl_certificate ssl_key/server.crt;  #线上购买后会生成正规的证书
        ssl_certificate_key ssl_key/server.key;

        location / {
                proxy_pass https://web_cluster;
                include nginx_params;

        }
}
server {
        listen 80;
        server_name blog.benet.com;
        return 302 https://$server_name$1;
}
保存退出
先不要重启服务

这里还没有加密证书文件,需要拷贝过来

[root@localhost ~]# scp -rp [email protected]:/etc/nginx/ssl_key /etc/nginx
The authenticity of host '192.168.10.6 (192.168.10.6)' can't be established.
ECDSA key fingerprint is 48:f0:af:77:9c:03:5c:b5:ca:8f:cd:47:72:1e:5e:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.6' (ECDSA) to the list of known hosts.
[email protected]'s password: 
server.key                                           100% 1704     1.7KB/s   00:00    
server.crt                                           100% 1334     1.3KB/s   00:00    
[root@localhost ~]# systemctl restart nginx

客户端修改/etc/hosts文件,域名指定lb1
访问测试:输入https://blog.benet.com或blog.benet.com都可以。

会提示:
在这里插入图片描述
添加例外,最后熟悉的界面又来啦,刷新
在这里插入图片描述
在这里插入图片描述

发布了39 篇原创文章 · 获赞 3 · 访问量 6443

猜你喜欢

转载自blog.csdn.net/weixin_43815140/article/details/105515065
今日推荐