centos7配置OpenSSL
时间: 2023-08-28 19:08:04 浏览: 55
在 CentOS 7 上安装和配置 OpenSSL 非常简单,可以按照以下步骤进行操作:
1. 安装 OpenSSL:
```
sudo yum install openssl
```
2. 检查 OpenSSL 版本:
```
openssl version
```
3. 生成 SSL 证书:
```
openssl req -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr
```
这里的 `example.com.key` 是生成的私钥文件,`example.com.csr` 是证书签名请求文件。
4. 生成自签名证书:
```
openssl x509 -req -days 365 -in example.com.csr -signkey example.com.key -out example.com.crt
```
这里的 `example.com.crt` 是生成的自签名证书文件。
配置 SSL 证书后,可以在 Web 服务器中启用 HTTPS。例如,在 Apache HTTP 服务器中启用 HTTPS,可以将以下代码添加到 Apache 配置文件中:
```
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /path/to/example.com.crt
SSLCertificateKeyFile /path/to/example.com.key
</VirtualHost>
```
然后重启 Apache 服务器:
```
sudo systemctl restart httpd
```
这样就可以通过 HTTPS 访问网站了。