目录
sudo apt-get install apache2
sudo systemctl start apache2
sudo apache2ctl -M
命令查询到现有模块如下,未找到ssl相关模块
apache2-dev模块包含了ssl模块,安装后先载入ssl模块,再重启apache2服务:
- sudo a2enmod ssl
-
- sudo systemctl restart apache2
已经成功加载ssl_module模块
由于是测试环境,先自己生成证书,如生产环境,可导入企业证书。
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.test.com"
将默认default-ssl.conf配置文件拷贝到apache2的扩展目录下,
- sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/
-
- cd /etc/apache2/sites-enabled/
-
- sudo vim default-ssl.conf
将配置中的证书文件改成自己的,以下是上面生成的私有证书:
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
如果用自己的域名,配置文件需要加上ServerName
sudo systemctl restart apache2
生产站点的目录权限问题请自行处理。