在 CentOS 上“加密 Apache2(httpd)”通常指 启用 HTTPS(TLS/SSL 加密)。CentOS 默认使用 httpd 而非 apache2(apache2 是 Debian/Ubuntu 的叫法)。下面以 CentOS 7/8 + httpd 为例说明。
# CentOS 7
yum install httpd mod_ssl -y
# CentOS 8
dnf install httpd mod_ssl -y
安装后会生成:
/etc/httpd/conf.d/ssl.confopenssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/pki/tls/private/localhost.key \
-out /etc/pki/tls/certs/localhost.crt
yum install certbot python2-certbot-apache -y
certbot --apache
编辑:
vi /etc/httpd/conf.d/ssl.conf
关键配置:
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
RewriteEngine On
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
</VirtualHost>
systemctl enable httpd
systemctl start httpd
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
curl -I https://localhost
浏览器访问:
https://your-server-ip
mod_ssl + 权限控制如果你指的是:
可以告诉我具体场景。