https创建证书

需要下载httpd模块:yum install httpd -y

前提需要先搭建一个虚拟主机来测试证书创建的效果,以下面www.hehe.com为例,可以参考创建:

bash 复制代码
[root@localhost conf.d]# vim vhost.conf 
<directory /www>
allowoverride none
require all granted
</directory>

<virtualhost 192.168.54.131:443> #端口要改为443
documentroot /www/hehe
servername www.hehe.com
alias /hehe /usr/local/mysecret #目录别名
</virtualhost>

虚拟主机创建完成后,再去创建对应的目录和文件,以及写入网页的内容:

bash 复制代码
[root@localhost conf.d]# mkdir /www/hehe
[root@localhost conf.d]# echo "hehe" >/www/hehe/index.html

在虚拟机本地解析和Windows本地解析文件中添加这条域名解析(虚拟机在/etc/hosts ,Windows在C:\Windows\System32\drivers\etc):

192.168.54.131 www.hehe.com

我们可以给www.hehe.com创建证书,具体创建证书步骤如下:

1.下载mod_ssl模块

bash 复制代码
[root@localhost conf.d]# yum install -y mod_ssl

2.生成密钥

bash 复制代码
[root@localhost certs]# openssl genrsa > jiami.key

3.移动密钥到/etc/pki/tls/private/

bash 复制代码
[root@localhost certs]# mv jiami.key ../private/

4.返回到certs目录下创建证书

bash 复制代码
[root@localhost certs]# openssl req -utf8 -new -key ../private/jiami.key -x509 -days 100 -out jiami.crt
Country Name (2 letter code) [XX]:86 #证书的地区:86 中国
State or Province Name (full name) []:rhce 
Locality Name (eg, city) [Default City]:shaaxi 
Organization Name (eg, company) [Default Company Ltd]:xi'an #组织
Organizational Unit Name (eg, section) []:peihua #组织单位
Common Name (eg, your name or your server's hostname) []:www.hehe.com #给证书的域名
Email Address []:anmin@hehe.com #邮箱

5.修改ssh.conf配置文件,内容如下:

bash 复制代码
[root@localhost certs]# vim /etc/httpd/conf.d/ssl.conf
#将密钥文件的目录改一下
SSLCertificateFile /etc/pki/tls/certs/jiami.crt
SSLCertificateKeyFile /etc/pki/tls/private/jiami.key

注意:在配置文件中找到这两行修改一下就行,不用修改其他的内容

6.关闭防火墙,重启服务

bash 复制代码
[root@localhost certs]# systemctl stop firewall.server
[root@localhost certs]# systemctl restart httpd

7.浏览器访问,查看证书

bash 复制代码
https://www.hehe.com/

8.如果要显示hehe页面内容,需要单独为这个虚拟主机配置,如下:

bash 复制代码
[root@localhost conf.d]# vim vhost.conf 
<directory /www>
allowoverride none
require all granted
</directory>

<virtualhost 192.168.54.131:443> #端口要改为443
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/jiami.crt
SSLCertificateKeyFile /etc/pki/tls/private/jiami.key
documentroot /www/hehe
servername www.hehe.com
alias /hehe /usr/local/mysecret
</virtualhost>

重启服务就可以了(systemctl restart)

相关推荐
碎梦归途4 小时前
思科网络设备配置命令大全,涵盖从交换机到路由器的核心配置命令
linux·运维·服务器·网络·网络协议·路由器·交换机
徐同保4 小时前
解决 Vue 3 项目 TypeScript 编译错误:@types/lodash 类型定义不兼容
redis·网络协议·https
Python+JAVA+大数据9 小时前
TCP_IP协议栈深度解析
java·网络·python·网络协议·tcp/ip·计算机网络·三次握手
skywalker_1110 小时前
网络编程篇
java·网络协议·网络编程
2501_9159214311 小时前
傻瓜式 HTTPS 抓包,简单抓取iOS设备数据
android·网络协议·ios·小程序·https·uni-app·iphone
青青小陌12 小时前
【UDS诊断--物理寻址VS功能寻址】
网络协议·信息与通信
路由侠内网穿透.12 小时前
fnOS 飞牛云 NAS 本地部署私人影视库 MoonTV 并实现外部访问
运维·服务器·网络·数据库·网络协议
2501_9159184114 小时前
把 iOS 性能监控融入日常开发与测试流程的做法
android·ios·小程序·https·uni-app·iphone·webview
霍格沃兹测试学院-小舟畅学15 小时前
Playwright处理WebSocket的测试方法
网络·websocket·网络协议