温馨提示×

centos apache2如何加密

小樊
48
2026-09-09 00:15:38
栏目: 网络安全

CentOS 上(注意:CentOS 默认是 Apache HTTP Server,包名通常是 httpd,不是 apache2apache2 是 Debian/Ubuntu 的叫法),“加密”一般指的是 HTTPS(SSL/TLS)加密。下面给你几种常见做法。


一、使用 Let’s Encrypt 免费证书(推荐)

1. 安装 EPEL 和 Certbot

yum install epel-release -y
yum install certbot python2-certbot-apache -y

2. 申请并自动配置 SSL

certbot --apache -d example.com -d www.example.com

按提示操作即可,Certbot 会自动:

  • 生成证书
  • 修改 Apache 配置
  • 开启 HTTPS

3. 自动续期

certbot renew --dry-run

(CentOS 下一般会自动加 cron / systemd timer)


二、使用自签名证书(测试用)

1. 生成私钥和证书

openssl req -x509 -nodes -days 365 \
  -newkey rsa:2048 \
  -keyout /etc/pki/tls/private/apache.key \
  -out /etc/pki/tls/certs/apache.crt

2. 配置 Apache SSL

yum install mod_ssl -y

编辑:

vi /etc/httpd/conf.d/ssl.conf

修改关键项:

SSLCertificateFile /etc/pki/tls/certs/apache.crt
SSLCertificateKeyFile /etc/pki/tls/private/apache.key

3. 重启 Apache

systemctl restart httpd

三、强制 HTTP 跳转到 HTTPS

在网站配置中加入:

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / https://example.com/
</VirtualHost>

四、基础安全加固(可选但建议)

  • 禁用不安全的 SSL/TLS 版本
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
  • 使用强加密套件
  • 开启 HSTS

五、常见误区提醒

✅ CentOS 用 httpd
❌ 不是 apache2(那是 Ubuntu)


如果你能告诉我:

  • CentOS 版本(6 / 7 / 8 / Stream)
  • Apache 是否已安装
  • 是公网域名还是内网测试

我可以给你完全对应的命令

0