我正在 Google 的 Compute Engine 上设置我的 Ubuntu 16.04 VM。我已经安装了 Apache,它已经在 HTTP 上托管我的域,我想启用 HTTPS。
迄今采取的措施:
- 更改 IP短暂的到静止的:Google Cloud Platform > 网络 > VPC 网络 > 外部 IP 地址
- 为静态 IP 添加“A”记录:domains.google.com > 我的域 > 编辑 DNS
- 以下是运行的命令(我使用了我的真实域名,而不是“example.com”)...
命令
sudo mkdir -p /var/www/example.com/html
sudo chmod -R 755 /var/www
cd /etc
sudo wget https://dl.eff.org/certbot-auto
sudo chmod a+x certbot-auto
cd /etc/apache2/sites-available
sudo cp 000-default.conf example.com.conf
新的会议文件包含以下内容:
<VirtualHost *:80 *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我已启用新的虚拟主机文件并重新加载
sudo a2ensite example.com.conf
sudo service apache2 reload
此时,我应该可以运行 Let's Encrypt 了
sudo certbot --apache -d example.com
我收到的错误是:
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: example.com
Type: unauthorized
Detail: Invalid response from
http://example.com/.well-known/acme-challenge/MFEvXhKDwEPPKmNM1EyGky1YG9mAvH0e7i0Z_gqsbUc:
"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p"
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address.
我可以手动创建目录/var/www/example.com/html/.well-known/acme-challenge
,也可以向其中写入文件。
非常感谢您的帮助!我已经为这个问题烦恼了 2 个晚上。
解决方案更新:按照@RalfFriedl 的回答生成 SSL 证书后,下面是安装该证书的步骤:
- 创造会议端口 HTTP 流量和 HTTPS 流量的文件
cd /etc/apache2/sites-available sudo nano example.com.conf
这会议文件将包含以下内容:
<VirtualHost *:80> ServerAdmin [email protected]
ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/html # always redirect HTTP traffic to HTTPS Redirect permanent / https://example.com/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
sudo nano example.com-https.conf
这会议文件将包含以下内容:
<VirtualHost *:443> ServerAdmin [email protected]
DocumentRoot /var/www/example.com/html ServerName example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost>
- 确保已安装 SSL 模块,然后启用新的会议,然后重新加载 Apache 服务器
sudo a2enmod rewrite sudo a2enmod ssl sudo a2ensite example.com-https.conf sudo service apache2 reload
答案1
Let's Encrypt 会验证该域名是否归您所有。为此,它将从您域名的 URL 中检索文件,在本例中为http://example.com/.well-known/acme-challenge/MFEvXhKDwEPPKmNM1EyGky1YG9mAvH0e7i0Z_gqsbUc
。certbot 似乎无法从您的 apache 配置中找出这一点。
尝试一下
sudo certbot --webroot --webroot-path /var/www/example.com/html -d example.com