在 Debian 上,Apache2 的“加密”通常指两种场景:
下面分别说明。
sudo apt update
sudo apt install apache2
sudo a2enmod ssl
sudo systemctl restart apache2
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com
自动完成:
证书续期:
sudo certbot renew
sudo openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/ssl/private/apache-selfsigned.key \
-out /etc/ssl/certs/apache-selfsigned.crt
创建站点配置:
sudo nano /etc/apache2/sites-available/ssl.conf
示例:
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
</VirtualHost>
启用:
sudo a2ensite ssl.conf
sudo systemctl reload apache2
sudo apt install apache2-utils
sudo htpasswd -c /etc/apache2/.htpasswd user1
<Directory /var/www/html/private>
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
重载 Apache:
sudo systemctl reload apache2
编辑:
sudo nano /etc/apache2/mods-enabled/ssl.conf
建议:
可用工具:
sudo apt install apache2-doc
journalctl -u apache2
如果你是指:
可以告诉我具体需求,我可以给你更精确的配置。