158 字
1 分钟
Apache 服务器安装, 配置 HTTPS
Apache服务器安装,配置HTTPS
Debian环境,安装Apache2,使用acme.sh配置https
安装Apache2
# apt install apache2
安装acme.sh
$ curl https://get.acme.sh | sh -s email=my@example.com
$ source ~/.bashrc
签发证书
$ acme.sh --issue -d mydomain.com -d www.mydomain.com --apache
签发前请确保相关域名已正确解析到该server上。
安装证书
$ acme.sh --install-cert -d mydomain.com \
--cert-file /path/to/cert.pem \
--key-file /path/to/key.pem \
--fullchain-file /path/to/fullchain.pem \
--reloadcmd "systemctl restart apache2"
这个命令同时会用于刷新证书,请确保reloadcmd正常工作
修改apache2配置
# vim /etc/apache2/sites-available/default-ssl.conf
...
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
SSLCertificateChainFile /path/to/fullchain.pem
...
启用SSL
# a2enmod ssl
# a2ensite default-ssl.conf
http重定向到https
# vim /etc/apache2/sites-available/000-default.conf
...
ServerName mydomain.com
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R=301]
...
# a2enmod rewrite
重启apache2
# systemctl restart apache2
Apache 服务器安装, 配置 HTTPS
https://shsuco.com/posts/apache2-配置https/