这个问题
我想了解如何实现从http到https的redirect,使用Apache2和Certbot的authentication。
细节
在运行Ubuntu 16.04的全新服务器上,我安装了一个“完美服务器”设置 (ISPConfig,Postfix,Dovecot和家族),以便运行一个小型的电子邮件服务器。
我也使用Certbot来安装SSL证书。 在使用Certbot之前,我手动将ServerName my.domain.com添加到我在/etc/apache2/sites-available/目录中find的四个文件中。
…还有这个文件:
我的理解是,这给了Certbot有关服务器上存在的域名的信息,并确保遇到的挑战。 (也许这是矫枉过正的?也许只编辑`apache2.conf?
然后我跑了:
certbot --apache -d my.domain.com
在安装过程中,我select了redirect选项:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. ------------------------------------------------------------------------------- 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
这是Certbot所做的承诺:
Redirecting vhost in /etc/apache2/sites-enabled/000-apps.vhost to ssl vhost in /etc/apache2/sites-enabled/000-ispconfig.vhost
但是,有两个问题:
# ls -al /etc/apache2/sites-available/ total 36 drwxr-xr-x 2 root root 4096 Nov 9 17:29 . drwxr-xr-x 9 root root 4096 Nov 9 16:44 .. -rw-r--r-- 1 root root 1336 Nov 9 14:35 000-default.conf -rw-r--r-- 1 root root 1340 Nov 9 16:44 apps.vhost -rw-r--r-- 1 root root 1200 Nov 9 16:33 apps.vhost.save -rw-r--r-- 1 root root 6387 Nov 9 15:08 default-ssl.conf -rw-r--r-- 1 root root 1929 Nov 9 12:36 ispconfig.conf -rw-r--r-- 1 root root 3349 Nov 9 16:44 ispconfig.vhost
现在,当我连接到http://my.domain.com时 ,我看到了Apache2 Ubuntu Default Page,没有redirect。 如果我连接到https://my.domain.com ,那么所有的浏览器告诉我,有一个问题。 Firefox是最明确的:
Secure Connection Failed An error occurred during a connection to my.domain.com. SSL received a record that exceeded the maximum permissible length. Error code: SSL_ERROR_RX_RECORD_TOO_LONG The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
但是,当我通过https:// http://my.domain.com:8080 /访问ISPConfig页面时,一切正常。 浏览器很高兴向我展示地址栏右侧的绿色“安全”标志。
访问http:// http://my.domain.com:8080 /有礼貌,但不是那么成功:
Bad Request Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.
我注意到Certbot已经对/etc/apache/sites-available/ispconfig.vhost文件进行了修改。 在下面的摘录中,标有---的行已被删除,并添加了+++行。
# SSL Configuration SSLEngine On SSLProtocol All -SSLv3 --- SSLCertificateFile /usr/local/ispconfig/interface/ssl/ispserver.crt --- SSLCertificateKeyFile /usr/local/ispconfig/interface/ssl/ispserver.key #SSLCACertificateFile /usr/local/ispconfig/interface/ssl/ispserver.bundle SSLCipherSuite ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-S$ SSLHonorCipherOrder On <IfModule mod_headers.c> Header always add Strict-Transport-Security "max-age=15768000" RequestHeader unset Proxy early </IfModule> SSLUseStapling On SSLStaplingResponderTimeout 5 SSLStaplingReturnResponderErrors Off +++ SSLCertificateFile /etc/letsencrypt/live/my.domain.com/fullchain.pem +++ SSLCertificateKeyFile /etc/letsencrypt/live/my.domain.com/privkey.pem +++ Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost>
(Certbot还在/etc/letsencrypt/中添加了一个包含所有authentication优点的目录。)
我的目标
我试图了解我需要对/etc/apache2/sites-available的文件进行哪些更改,以便将http://my.domain.com默认redirect到https://my.domain.com ,主站点以及端口8080上的ISPConfig页面。
换句话说,我想知道怎么做真正的文件,什么Certbot说,它会做的文件,只存在于其想象。
这里的主要问题是重复configuration中的服务器条目。 因此,可能只有一些服务器configuration选项被Apache加载。
certbot --apache (运行没有certonly选项)读取Web服务器configuration,并尝试自动更新其获得证书的网站的configuration。 如果在Web服务器configuration中有多个网站条目,它可能会更新一个没有被读取的configuration – 我想这就是发生了什么。
有几种不同的方法来组织Web服务器configuration文件,并且很容易混淆它们。 你打算使用哪一个? 此服务器故障问题可能会有帮助
编辑:重新阅读有关certbotredirect的问题 – 删除certbot添加的行,并运行certbot apache -d example.com组织后,应该允许certbot自动添加redirect选项。