要在Apache2上部署SSL证书,您需要遵循以下步骤:
获取SSL证书:首先,您需要从证书颁发机构(CA)购买或获取免费的SSL证书。常见的免费证书颁发机构有Let’s Encrypt、ACME.sh等。
安装Apache2:确保您的系统已安装Apache2。在Debian和Ubuntu上,您可以使用以下命令安装:
sudo apt-get update
sudo apt-get install apache2
sudo a2enmod ssl
/etc/apache2/sites-available
目录下找到这些文件。创建一个名为yourdomain.com-le-ssl.conf
的新文件,其中yourdomain.com
是您的域名。在此文件中,添加以下内容:<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com
SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key
SSLCertificateChainFile /path/to/your/ca_bundle.crt
<Directory /var/www/yourdomain.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>
</IfModule>
请将/path/to/your/certificate.crt
、/path/to/your/private.key
和/path/to/your/ca_bundle.crt
替换为您的证书文件的实际路径。
sudo a2ensite yourdomain.com-le-ssl.conf
000-default.conf
文件:sudo nano /etc/apache2/sites-available/000-default.conf
找到<VirtualHost *:80>
部分,并在其中添加以下行:
Redirect permanent / https://yourdomain.com/
保存并关闭文件。
sudo systemctl restart apache2
sudo ufw allow 443/tcp
完成以上步骤后,您应该已经成功地在Apache2上部署了SSL证书。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: ubuntu pgadmin更新升级