配置apache2 SSL模块的443端口

1、开启SSL模块

a2enmod ssl

2、启用SSL站点

a2ensite default-ssl

3、加入监听端口

sudo vim /etc/apache2/ports.conf
#编辑Apache端口配置,加入443端口(HTTPS采用的443端口传输数据)
Listen 443

4、配置虚拟主机

编辑default-ssl文件,加入证书对应的主机头。

sudo vim /etc/apache2/sites-enabled/default-ssl
  
DocumentRoot /var/www/html
ServerName wp.cpxiang.tech

5、配置SSL证书(假设你的证书、私钥和证书链文件已经申请好)

按如下配置

SSLEngine on
SSLCertificateFile             /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile           /etc/ssl/private/ssl-cert-snakeoil.key
SSLCertificateChainFile          /etc/ssl/certs/server-ca.crt

重新启动Apache,然后http://wp.cpxiang.tech,测试下浏览器可能会报证书不合法。可以添加例外或者其他仍然访问就好了,自签名证书浏览器一般会提示不合法,配置完之后大家可以用抓包工具看下数据传输是否加密了。

发表评论?

2 条评论。

  1. 在000-*.conf中添加
    RewriteEngine on
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R=301]

  2. 强制HTTPS
    里面加入如下内容:
    RewriteEngine On
    RewriteRule ^(.*)$ http://%{HTTP_HOST}$1 [R,L]
    然后重启Apache, done!

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.