跳至正文
首页 » archlinux apache服务器https改造

archlinux apache服务器https改造

https

HTTPS的主要思想是在不安全的网路上建立一安全信道,并可在使用适当的加密套件和伺服器凭证可被验证且可被信任时,对窃听和中间人攻击提供合理的防护。现在很多网站已经采用了https。如果没有的话,使用chrome等浏览器会提示不安全。一些网站还提到是否采用https会影响网页在搜索引擎中的排名。本文将介绍 archlinux apache服务器https改造。

1 证书获取及服务器配置

certbot是一个自动配置服务器,获取证书的工具。使用以下命令安装cerbot及cerbot的apache支持插件。

pacman -S certbot certbot-apache 

创建文件/etc/httpd/conf/extra/httpd-acme.conf,输入以下内容

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/"> AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS
</Directory>

使/etc/httpd/conf/httpd.conf包含上面的文件

Include conf/extra/httpd-acme.conf

编辑/etc/httpd/conf/httpd.conf,去除以下行前的#

Include conf/extra/httpd-vhosts.conf

编辑/etc/httpd/conf/extra/httpd-vhosts.conf,根据里面以有示例,修改为适合自己服务器的版本。

执行以下命令,开始证书申请向导。

certbot --apache

2 wordpress配置

完成证书的获取和服务器配置后,使用Really Simple SSL插件可以实现全站到https的转移。

3自动更新证书

建立文件 /etc/systemd/system/certbot.service,输入下面内容。

[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --agree-tos

建立文件/etc/systemd/system/certbot.timer,并输入如下内容。

[Unit]
Description=Twice daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=0/12:00:00
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

enable并start服务

systemctl enable certbot.timer
systemctl start certbot.timer

4 删除证书

首先移动到/etc/letsencrypt/renewal/路径下,查看证书名称(该路径下的文件去掉文件拓展名.conf就是证书名称)。然后使用下面命令删除证书(将命令中的beekc.top换为前面查到的证书名称)。

certbot delete --cert-name beekc.top

5 常见问题

Q:httpd服务无法启动,报错’*****.pem’ does not exist or is empty
A:应该是没有可用的ssl证书。如果需要继续使用https相关服务,则使用certbot certonly –email email@example.com –webroot -w /var/lib/letsencrypt/ -d domain.tld命令后即可启动httpd服务。如果想退回http服务,则需要在appache服务器配置中产出https相关配置信息。

Q:网站无法正常保存cookie
A:我为了减少网站重定义次数,把网站的域名从beekc.top修改成了beekc.top。之后进入后台登陆无法保存信息,每次刷新都需要重新登陆。后来发现原因是没有更新ssl证书信息。删除原来的证书,使用新的域名注册后问题解决。

6 参考

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注