HTTPS-02

一.HTTP证书
1.简介
对比          	域名型 DV	         企业型 OV	                     增强型 EV

绿色地址栏	     小锁标记+https	     小锁标记+https	             小锁标记+企业名称+https


一般用途	     个人站点和应用;      电子商务站点和应用;           大型金融平台;
               简单的https加密需求   中小型企业站点         	     大型企业和政府机构站点

审核内容	    域名所有权验证	        全面的企业身份验证;           最高等级的企业身份验证; 
                                    域名所有权验证
               
颁发时长	     10分钟-24小时	         3-5个工作日	             5-7个工作日

单次申请年限	    1年	                  1-2年	                    1-2年

赔付保障金	   ——	                  150万美金左右	1             200万美金

2证书购买选择
1.保护单个域名 www.mm.com
2.保护五个域名 www images cdn test 
3.通配符域名 *.linux12.com
3.HTTPS证书注意事项
1.https证书不支持续费,证书到期需要重新申请并进行替换

2.https不支持三级域名解析,如 test.m.linux12.com

3.https显示绿色,说明整个网站的url都是https的

	# https显示黄色,因为网站代码中包含http的不安全链接
	# https显示红色,那么证书是假的或者证书过期
二、单台HTTPS配置 — 假证书
1.检查nginx
[root@web01 ~]# nginx -V
--with-http_ssl_module    ---有这个模块是支持
2.创建证书存放目录
[root@web01 ~]# mkdir /etc/nginx/ssl_key
[root@web01 ~]# cd /etc/nginx/ssl_key/
3.造假证书
# 1、生成私钥
#使用openssl命令充当CA权威机构创建证书(生产不使用此方式生成证书,不被互联网认可的黑户证书)

[root@web01 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: 123456   # 密码6位
Verifying - Enter pass phrase for server.key: 123456

[root@web01 ssl_key]# ll
total 4
-rw-r--r--. 1 root root 1739 Dec  9 11:27 server.key

# 2、生成公钥
#生成自签证书(公钥),同时去掉私钥的密码
[root@web01 ssl_key]# openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
[root@web01 ssl_key]# openssl req -days 36500 -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]:cn
State or Province Name (full name) []:riben
Locality Name (eg, city) [Default City]:sh
Organization Name (eg, company) [Default Company Ltd]:skz
Organizational Unit Name (eg, section) []:mm
Common Name (eg, your name or your server's hostname) []:mm
Email Address []:1234@qq.com

# req  --> 用于创建新的证书
# new  --> 表示创建的是新证书    
# x509 --> 表示定义证书的格式为标准格式
# key  --> 表示调用的私钥文件信息
# out  --> 表示输出证书文件信息
# days --> 表示证书的有效期
# sha256 --> 加密方式

# 3、查看生成的证书
[root@web01 ssl_key]# ll
total 8
-rw-r--r-- 1 root root 1342 Apr  8 15:00 server.crt
-rw-r--r-- 1 root root 1708 Apr  8 15:00 server.key

4.配置证书语法
## 模块 ngx_http_ssl_module.html

#1.开启证书
Syntax:	ssl on | off;
Default:	ssl off;
Context:	http, server

#2.指定证书文件
Syntax:	ssl_certificate file;
Default:	—
Context:	http, server

#3.指定私钥文件
Syntax:	ssl_certificate_key file;
Default:	—
Context:	http, server
5.配置nginx证书
# 1.配置假证书
[root@web01 ~]# vim /etc/nginx/conf.d/linux12.ssl.com.conf 
server {
    listen 443 ssl;
    server_name linux12.ssl.com;
    ssl_certificate /etc/nginx/ssl_key/server.crt;
    ssl_certificate_key /etc/nginx/ssl_key/server.key;

    location / {
        root /mm/a;
        index index.html;
    }
}

## nginx -t检查并重启
[root@web01 ~]# systemctl restart nginx	
6.配置本地hosts
10.10.0.7 linux12.ssl.com
7.配置http自动跳转https
[root@web01 ~]# vim /etc/nginx/conf.d/linux12.ssl.com.conf 
server {
    listen 443 ssl;
    server_name linux12.ssl.com;
    ssl_certificate /etc/nginx/ssl_key/server.crt;
    ssl_certificate_key /etc/nginx/ssl_key/server.key;

    location / {
        root /mm/a;
        index index.html;
    }
}
server {
    listen 80;
    server_name linux12.ssl.com;

    rewrite (.*) https://$server_name$1;
    #return 302 https://$server_name$request_uri;
}

## nginx -t检查并重启
[root@web01 ~]# systemctl restart nginx

三、全站HTTPS
1、环境准备
主机	    内网IP	     外网IP	      身份

lb01	172.16.1.5	   10.10.0.5	负载均衡

web01	172.16.1.7		            web服务器

web02	172.16.1.8		            web服务器
2.配置web服务器
# 1、配置nginx
[root@web01 conf.d]# cat linux12.https.com.conf 
server {
    listen 80;
    server_name linux12.https.com;

    location / {
        root /mm/https;
        index index.html;
    }
}

## nginx -t检查并重启
[root@web01 conf.d]# cat linux12.https.com.conf 
server {
    listen 80;
    server_name linux12.https.com;

    location / {
        root /mm/https;
        index index.html;
    }
}
## nginx -t检查并重启
[root@web01 ~]# systemctl restart nginx	
3、配置站点
## web01服务端

[root@web01 ~]# mkdir /mm/https
[root@web01 ~]# echo "web01html" > /mm/https/index.html
[root@web01 ~]# chown -R www.www /mm/https/

## web02服务端

[root@web02 ~]# mkdir /mm/https
[root@web02 ~]# echo "web02html" > /mm/https/index.html
[root@web02 ~]# chown -R www.www /mm/https/
4.配置本地hosts
10.10.0.8 linux12.https.com
10.10.0.7 linux12.https.com
5.配置负载均衡
# 1、配置证书
[root@web01 ~]# scp -r /etc/nginx/ssl_key 172.16.1.5:/etc/nginx/

#2、配置nginx
[root@lb01 ~]# vim /etc/nginx/conf.d/linux12.https.com.conf
upstream web_https {
    server 172.16.1.7:80;
    server 172.16.1.8:80;
}
server {
    listen 80;
    server_name linux12.https.com;

    rewrite (.*) https://$server_name$1;
}
server {
    listen 443 ssl;
    server_name linux12.https.com;
    ssl_certificate /etc/nginx/ssl_key/server.crt;
    ssl_certificate_key /etc/nginx/ssl_key/server.key;

    location / {
        proxy_pass http://web_https;
        include proxy_params;
    }
}
## nginx -t检查并重启
[root@web01 ~]# systemctl restart nginx	
6.配置本地hosts
10.10.0.5 linux12.https.com
五、项目全站HTTPS
1、配置web文件
1.配置web端博客配置文件
[root@web01 ~]# vim /etc/nginx/conf.d/linux12.wp.com.conf 
server {
    listen 80;
    server_name linux12.wp.com;
    
    location / {
        root /mm/wordpress;
        index index.php;
    }   
    
    location ~* \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /mm/wordpress/$fastcgi_script_name;
        include fastcgi_params;
    }
}

## NFS机器开启nfs服务

[root@nfs ~]# systemctl restart nfs rpcbind

# web01、web02机器挂载

[root@web01 conf.d]# showmount -e 10.10.0.31
Export list for 10.10.0.31:
/data/wp 172.16.1.0/24
[root@web01 conf.d]# mount -t nfs 172.16.1.31:/data/wp /mm/wordpress/wp-content/uploads/

[root@web02 conf.d]# showmount -e 10.10.0.31
Export list for 10.10.0.31:
/data/wp 172.16.1.0/24
[root@web02 conf.d]# mount -t nfs 172.16.1.31:/data/wp /mm/wordpress/wp-content/uploads/

# db01机器开启数据库

[root@db01 ~]# systemctl restart mariadb
2.配置负载均衡
先备份一份 linux12.wp.com.conf.bak
[root@lb01 conf.d]# cp linux12.wp.com.conf linux12.wp.com.conf.bak

[root@lb01 conf.d]# vi linux12.wp.com.conf
upstream blog {
    server 172.16.1.7;
    server 172.16.1.8;
}

server {
    listen 80;
    server_name linux12.wp.com;

    rewrite (.*) https://$server_name$1;
}

server {
    listen 443 ssl;
    server_name linux12.wp.com;
    ssl_certificate /etc/nginx/ssl_key/server.crt;
    ssl_certificate_key /etc/nginx/ssl_key/server.key;

    location / {
        proxy_pass http://blog;
        include proxy_params;
    }
}
## nginx -t检查并重启
[root@web01 ~]# systemctl restart nginx	
3.配置本地hosts
10.10.0.5 linux12.wp.com
4、页面格式错乱问题
问题:因为负载均衡请求web端是http请求,web端请求php也是http格式,php返回的内容就是http格式的内容,我们浏览器请求的是https,所以格式显示错乱,我们需要配置让php返回的格式是https格式
# 1.配置wenb01文件
[root@web01 ~]# vim /etc/nginx/conf.d/linux12.wp.com.conf 
server {
    listen 80;
    server_name linux12.wp.com;

    location / {
        root /mm/wordpress;
        index index.php;
    }

    location ~* \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /mm/wordpress/$fastcgi_script_name;
        #开启https模式
        fastcgi_param HTTPS on;
        include fastcgi_params;
    }
}
## nginx -t检查并重启web01
[root@web01 ~]# systemctl restart nginx	

# 把web01的文件发送给web02
[root@web01 conf.d]# scp -r linux12.wp.com.conf 172.16.1.8:/etc/nginx/conf.d/

## nginx -t检查并重启web02
[root@web02 ~]# systemctl restart nginx	
## nginx -t检查并重启lb01
[root@lb01 ~]# systemctl restart nginx	

2、ssl证书优化参数 --了解
server {
    listen 443 default_server;
    server_name blog.driverzeng.com driverzeng.com;
    ssl on;
    root /var/www/wordpress;
    index index.php index.html index.htm;
    ssl_certificate   ssl/215089466160853.pem;
    ssl_certificate_key  ssl/215089466160853.key;
    
    ssl_session_cache shared:SSL:10m; #在建立完ssl握手后如果断开连接,在session_timeout时间内再次连接,是不需要再次获取公钥建立握手的,可以服用之前的连接
    ssl_session_timeout 1440m;  #ssl连接断开后的超时时间
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #配置加密套接协议
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;  #使用TLS版本协议
    ssl_prefer_server_ciphers on;  #nginx决定使用哪些协议与浏览器通信

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FikL-09-19

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值