IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> PHP知识库 -> HTTPS证书基本概述 -> 正文阅读

[PHP知识库]HTTPS证书基本概述

https证书

为什么需要使用HTTPS
因为 HTTP 不安全,当我们使用 http 网站时,会遭到劫持和篡改,如果采用 https 协议,那么数据在传输过程中是加密的,所以黑客无法窃取或者篡改数据报文信息,同时也避免网站传输时信息泄露。
https证书:ssl协议 ??

在数据进行加密与解密过程中,如何确定双方的身份?

此时就需要有一个权威机构来验证双方身份,那么这个权威机构就是CA机构。

那么CA机构又是如何颁发证书?

我们首先需要申请证书,先去登记机构进行身份登记然后登记机构再通过CSR发给CA,CA中心通过后会生成一堆公钥和私钥,公钥会在CA证书链中保存,公钥和私钥证书我们拿到后,会将其部署在WEB服务器上

?模拟网站被篡改?

# web01上编写nginx配置文件
[root@web01 conf.d]# vim zhuzhan.conf
server {
   listen 80;
   server_name www.zhuzhan.com;
   location / {
       root /zhuzhan;
       index index.html;
   }
}
# 创建站点目录,编辑默认页面
[root@web01 conf.d]# mkdir /zhuzhan
[root@web01 conf.d]# vim /zhuzhan/index.html
<!DOCTYPE html>
<html lang="zh">
<head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>这个网站要被篡改了</title>
</head>
<body>
 <h1>曾老湿主站点</h1>
 <img src="https://img11.51tietu.net/pic/2016-
071418/20160714181543xyu10ukncwf221991.jpg" alt="">
 <p>这里是曾老湿站点 曾老湿版权所有</p>
</body>
</html>

# 黑客攻击
server {
   listen 80;
   server_name www.zhuzhan.com;
   location / {
       proxy_pass http://172.16.1.7;
       include /etc/nginx/proxy_params;
       sub_filter '<title>这个网站要被篡改了</title>' '<title>这个网站已经被篡改了
</title>';
       sub_filter '<p>这里是曾老湿站点 曾老湿版权所有</p>' '<p>不是曾老湿版权所有
</p>';
       sub_filter '<img src="https://img11.51tietu.net/pic/2016-
071418/20160714181543xyu10ukncwf221991.jpg" a
lt="">' '<img src="https://blog.driverzeng.com/zenglaoshi/xingganheguan.gif">';
   }
}

单台web实现证书

证书的类型

域名型 企业型 OV增强型 EV
绿色地
址栏??
小锁标记+https小锁标记+https小锁标记+企业名称+https
一般用
途?
个人站点和应用; 简单的
https加密需求
电子商务站点和应用; 中小
型企业站点
大型金融平台; 大型企业和政
府机构站点
审核内
域名所有权验证全面的企业身份验证; 域名
所有权验证
最高等级的企业身份验证; 域
名所有权验证
颁发时
10分钟-24小时?3-5个工作日5-7个工作日
单次申
请年限
1年1-2年?1-2年?
赔付保
障金
0125-175万美金125-175万美金

证书选择

保护一个域名 www
保护五个域名 www images cdn test m
通配符域名 *.xxxxx.com

https注意事项

https 不支持续费,证书到期需要重新申请并进行替换 https 不支持三级域名解析,
test.m.driverzeng.com https
显示绿色,说明整个网站的 url 都是 https
https 显示黄色,因为网站代码中包含 http 的不安全链接
https 显示红色, 那么证书是假的或者证书过期。

web证书实现


# 1.查看nginx是否支持ssl证书
[root@web01 conf.d]# nginx -V
--with-http_ssl_module
# 2.创建证书的目录
[root@web01 ~]# mkdir /etc/nginx/ssl
# 3.进入证书目录
[root@web01 ~]# cd /etc/nginx/ssl
# 4.生成证书
[root@web01 ssl]# 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:
Verifying - Enter pass phrase for server.key:
# 5.自签证书
[root@web01 ssl]# 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.
-----
# 国家名,最多2个字符
Country Name (2 letter code) [XX]:CN
# 省全称
State or Province Name (full name) []:Shanghai
# 城市全称
Locality Name (eg, city) [Default City]:Shanghai
# 公司名
Organization Name (eg, company) [Default Company Ltd]:niubi
# 公司名
Organizational Unit Name (eg, section) []:niu
# 证书要保护的域名
Common Name (eg, your name or your server's hostname) []:blog.tjh.com
# 邮件
Email Address []:123@qq.com

配置ssl证书

server {
   listen 443 ssl;
   server_name blog.tjh.com;
   root /code/wordpress;
   ssl_certificate  /etc/nginx/ssl/server.crt;
   ssl_certificate_key /etc/nginx/ssl/server.key;
}

80强转443

vim /etc/nginx/conf.d/blog.tjh.com.conf
server {
   listen 80;
   server_name blog.tjh.com;
#    return 302 https://$server_name$request_uri;
   rewrite (.*) https://$server_name$1 redirect;
}

nginx集群实现HTTPS实践

环境准备

?部署web

# web01
server {
listen 80;
server_name blog.tjh.com;
root /code/wordpress;
    #ssl_certificate  /etc/nginx/ssl/server.crt;
    #ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
   index index.php index.html;
        if ( -f $request_filename/index.html ){
           rewrite (.*) $1/index.html break;
       }
        if ( -f $request_filename/index.php ){
           rewrite (.*) $1/index.php;
       }
        if ( !-f $request_filename ){
           rewrite (.*) /index.php;
       }
        if ($http_user_agent ~*
"Wget|ApacheBench|webBench|isouSpider|MJ12bot|YoudaoBot|Tomato|bingbot/2.0|compatible"
){
            set $block_user_agent 1;
       }
        if ($block_user_agent = 1){
           return 403;
       }
}
location ~ \.php$ {
fastcgi_pass unix:/dev/shm/php71w.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
# web02
server {
listen 80;
server_name blog.tjh.com;
root /code/wordpress;
    #ssl_certificate  /etc/nginx/ssl/server.crt;
    #ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
   index index.php index.html;
        if ( -f $request_filename/index.html ){
           rewrite (.*) $1/index.html break;
       }
        if ( -f $request_filename/index.php ){
           rewrite (.*) $1/index.php;
       }
        if ( !-f $request_filename ){
           rewrite (.*) /index.php;
       }
        if ($http_user_agent ~*
"Wget|ApacheBench|webBench|isouSpider|MJ12bot|YoudaoBot|Tomato|bingbot/2.0|compatible"
){
            set $block_user_agent 1;
       }
        if ($block_user_agent = 1){
           return 403;
       }
}
location ~ \.php$ {
fastcgi_pass unix:/dev/shm/php71w.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
nginx -t
systemctl reload nginx

部署负载均衡

1.编写配置文件
[root@lb01 ~]# vim /etc/nginx/conf.d/blog.conf

upstream blog_abc_com {
	server 172.16.1.7;
	server 172.16.1.8;
}

server {
	listen 80;
	server_name blog.abc.com;
	rewrite (.*) https://$server_name$request_uri redirect;
}

server {
	listen 443 ssl;
	server_name blog.abc.com;
	ssl_certificate /etc/nginx/ssl/server.crt;
	ssl_certificate_key /etc/nginx/ssl/server.key;
	location / {
		proxy_pass http://blog_abc_com;
		include /etc/nginx/proxy_params;
	}
}

2. 创建证书存放目录
[root@lb01 ~]# mkdir /etc/nginx/ssl/

3.进入证书目录
[root@lb01 ~]# cd /etc/nginx/ssl

4.生成证书
[root@lb01 ssl]# openssl genrsa -idea -out server.key 2048

5.自签证书
[root@web01 ssl]# openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt

6.访问blog.abc.com

HTTPS导致wordpress破图

原因:前端使用443端口,web使用80端口,PHP程序走的80请求

解决方法:让PHP程序知道,前端使用的是443端口

location ~ \.php$ {
   fastcgi_pass unix:/dev/shm/php71w.sock;
 
# 告诉PHP走443端口
   fastcgi_param HTTPS on;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include /etc/nginx/fastcgi_params;
}

SSL优化参数

#在建立完ssl握手后如果断开连接,在session_timeout时间内再次连接,是不需要再次获取公钥建立握手的,可以服用之前的连接
ssl_session_cache shared:SSL:10m; 
#ssl连接断开后的超时时间
ssl_session_timeout 1440m; 
#配置加密套接协议
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#使用TLS版本协议
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;  
#nginx决定使用哪些协议与浏览器通信
ssl_prefer_server_ciphers on;  

blog配置优化

[root@lb01 conf.d]# cat blog.conf
upstream blog_abc_com {
        server 172.16.1.7;
        server 172.16.1.8;
}
# 防止恶意解析
server {
	listen 80;
	server_name _;
	rewrite (.*) https://blog.abc.com redirect;
}


server {
        listen 80;
        server_name blog.abc.com;

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

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

        location / {
                proxy_pass http://blog_abc_com;
                include /etc/nginx/proxy_params;
        }
}

  PHP知识库 最新文章
Laravel 下实现 Google 2fa 验证
UUCTF WP
DASCTF10月 web
XAMPP任意命令执行提升权限漏洞(CVE-2020-
[GYCTF2020]Easyphp
iwebsec靶场 代码执行关卡通关笔记
多个线程同步执行,多个线程依次执行,多个
php 没事记录下常用方法 (TP5.1)
php之jwt
2021-09-18
上一篇文章      下一篇文章      查看所有文章
加:2021-08-10 13:12:35  更:2021-08-10 13:14:21 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/13 16:55:36-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码