Apache
Apache
安装
# ubuntu
apt-get update
apt-get install apache2 openssl
开启HTTPS
- 开启模块
a2enmod ssl
a2enmod rewrite
- 修改Apache配置文件
vi /etc/apache2/apache2.conf
在最后增加以下文本
<Directory /var/www/html>
AllowOverride All
</Directory>
- 创建证书文件夹
mkdir /etc/apache2/certificate
cd /etc/apache2/certificate
创建证书以后扔进去。
- 修改默认配置文件
vi /etc/apache2/sites-enabled/000-default.conf
更改前
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
更改后
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt
SSLCertificateKeyFile /etc/apache2/certificate/apache.key
</VirtualHost>
HTTP跳转HTTPS
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</virtualhost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt
SSLCertificateKeyFile /etc/apache2/certificate/apache.key
</VirtualHost>
- 重启apache
service apache2 restart