Apache 配置 SSL 证书步骤
一 准备与前置检查
二 开放 443 端口与安全组
command -v nc >/dev/null 2>&1 || sudo yum install -y ncsudo ss -tlnp | grep -q ':443 ' || sudo nc -l 443 & sleep 1; nc -w 3 -vz <当前服务器的公网 IP> 443command -v nc >/dev/null 2>&1 || sudo apt-get install -y netcatsudo ss -tlnp | grep -q ':443 ' || sudo nc -l -p 443 & sleep 1; nc -w 3 -vz <当前服务器的公网 IP> 443sudo firewall-cmd --permanent --add-port=443/tcp && sudo firewall-cmd --reloadsudo ufw allow 443/tcpsudo nft add rule inet filter input tcp dport 443 counter accept(按需持久化)sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT(按需持久化)三 安装与配置 Apache
sudo yum install -y mod_ssl 或 sudo dnf install -y mod_sslsudo a2enmod sslhttpd -M | grep ssl_module 或 apachectl -M | grep ssl_module 应看到 ssl_module (shared)。cat domain_name_public.crt domain_name_chain.crt > domain_name_fullchain.pem,部署时仅使用 fullchain.pem 与 .key。<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/ssl/cert/domain_name_fullchain.pem
SSLCertificateKeyFile /etc/ssl/cert/domain_name.key
# 其他推荐参数
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
</VirtualHost>
sudo httpd -t 或 sudo apache2ctl -t(出现 Syntax OK 再继续)sudo systemctl reload httpd 或 sudo systemctl restart httpdsudo systemctl reload apache2 或 sudo systemctl restart apache2四 验证与常见问题
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R]
nc 测试连通性。httpd -t/apache2ctl -t 定位错误行并修正。