如何在没有证书(Apache VirtualHosts)的情况下将 HTTPS 请求重定向到 HTTP 并避免证书警告
How to redirect HTTPS requests to HTTP without a certificate (Apache VirtualHosts) and avoid a certificate warning
I would first like to first say, this is not good practice and we should endevour to have everything on HTTPS 100% of the time but in this case I had a series of awkward requirements on a system that did not hold sensitive information. I was quite ignorant of how HTTPS/TLS worked when asking this question back when I was more junior but have left it in place to help others as it receives a fair amount of attention. I recommend reading Oreily's TLS 101 if you're interested.
You can now get free TLS certificates using Let's Encrypt which I thoroughly recommend. Lastly, if you are using the default Apache config please check out Mozilla's SSL config generator selecting 'Modern' after entering your apache version.
我在一台 Apache 服务器上托管了几个独立的网站:
site.com
site.com 将所有用户从应用程序内重定向到 HTTPS。
example.com
example.com 是一个 HTTP 网站,HTTPS 请求被重定向到 HTTP
为了不让 https://example.com instead of http://example.com 的意外请求得到 site.com(因为当只使用一个 HTTPS 虚拟主机成为默认站点时)我需要为 example.com 但我必须使用自签名证书,因为网站没有理由使用 SSL。
这意味着当有人访问 https://example.com 时,他们会收到一个浏览器警告页面,表明 SSL 是自签名的,然后一旦他们单击继续,他们就会被重定向到 HTTP
有什么方法可以在没有证书的情况下将 HTTPS 请求重定向到 HTTP
这是当前虚拟主机:
<VirtualHost *:443>
ServerName about.example.com:443
DocumentRoot "/directory"
<Directory "/directoy">
AllowOverride All
Require all granted
</Directory>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/ExampleCOM.pem
SSLCertificateKeyFile /etc/httpd/ssl/AboutExampleCOM-key.pem
Header always set Strict-Transport-Security "max-age=15768000"
</VirtualHost>
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
SSLHonorCipherOrder on
# Disabled to avoid CRIME attack
SSLCompression off
# this usually compromises perfect forward secrecy
SSLSessionTickets off
# OCSP Stapling, httpd 2.3.3 or later
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLStaplingCache shmcb:/var/run/ocsp(128000)
从根本上说,这是个问题。当通过 HTTPS 通信时,TLS 通信层是在交换任何内容之前设置的,即关于证书的警告发生在关于网站的任何信息被传输之前。因此,无论是否定义了 https,无论是否自签名,都需要一个证书来允许浏览器连接。
理想情况下,对于 'best practice',我们真的应该鼓励人们默认使用 HTTPS(我意识到这是一种开销,而且证书可能会很烦人,虽然不应该自签名证书有什么问题,经常有问题和浏览器消息等)。
即使您有一个 'can only do http' 的应用服务器,最佳做法通常是在该应用服务器前面放置一个 Web 服务器(例如 nginx 或 lighthttpd 或某种形式的负载平衡器),这也将为您提供https 终止。 - 这似乎是您对将请求转发到您的网站的 httprewrite 所做的。
您可能会发现一些廉价的 SSL 证书提供程序,它们安装在大多数浏览器中?
简答。不,没有没有方法来做到这一点。
与 https 的连接发生在之前发生任何类型的重定向。您唯一能做的就是购买证书。如今,常规域证书非常便宜。
您可以获得一个有效的域证书 4.99 美元/年。然后进行重定向,使 https 和 http 都被覆盖。
或者您可以关闭 443 虚拟主机,但用户将收到 404 或连接错误页面。如果他们尝试 https。
这些是你的选择。只要它是自签名的并且是设计使然,您的用户将始终获得 警告页面 。
I would first like to first say, this is not good practice and we should endevour to have everything on HTTPS 100% of the time but in this case I had a series of awkward requirements on a system that did not hold sensitive information. I was quite ignorant of how HTTPS/TLS worked when asking this question back when I was more junior but have left it in place to help others as it receives a fair amount of attention. I recommend reading Oreily's TLS 101 if you're interested. You can now get free TLS certificates using Let's Encrypt which I thoroughly recommend. Lastly, if you are using the default Apache config please check out Mozilla's SSL config generator selecting 'Modern' after entering your apache version.
我在一台 Apache 服务器上托管了几个独立的网站:
site.com
site.com 将所有用户从应用程序内重定向到 HTTPS。
example.com
example.com 是一个 HTTP 网站,HTTPS 请求被重定向到 HTTP
为了不让 https://example.com instead of http://example.com 的意外请求得到 site.com(因为当只使用一个 HTTPS 虚拟主机成为默认站点时)我需要为 example.com 但我必须使用自签名证书,因为网站没有理由使用 SSL。
这意味着当有人访问 https://example.com 时,他们会收到一个浏览器警告页面,表明 SSL 是自签名的,然后一旦他们单击继续,他们就会被重定向到 HTTP
有什么方法可以在没有证书的情况下将 HTTPS 请求重定向到 HTTP
这是当前虚拟主机:
<VirtualHost *:443>
ServerName about.example.com:443
DocumentRoot "/directory"
<Directory "/directoy">
AllowOverride All
Require all granted
</Directory>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/ExampleCOM.pem
SSLCertificateKeyFile /etc/httpd/ssl/AboutExampleCOM-key.pem
Header always set Strict-Transport-Security "max-age=15768000"
</VirtualHost>
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
SSLHonorCipherOrder on
# Disabled to avoid CRIME attack
SSLCompression off
# this usually compromises perfect forward secrecy
SSLSessionTickets off
# OCSP Stapling, httpd 2.3.3 or later
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLStaplingCache shmcb:/var/run/ocsp(128000)
从根本上说,这是个问题。当通过 HTTPS 通信时,TLS 通信层是在交换任何内容之前设置的,即关于证书的警告发生在关于网站的任何信息被传输之前。因此,无论是否定义了 https,无论是否自签名,都需要一个证书来允许浏览器连接。
理想情况下,对于 'best practice',我们真的应该鼓励人们默认使用 HTTPS(我意识到这是一种开销,而且证书可能会很烦人,虽然不应该自签名证书有什么问题,经常有问题和浏览器消息等)。
即使您有一个 'can only do http' 的应用服务器,最佳做法通常是在该应用服务器前面放置一个 Web 服务器(例如 nginx 或 lighthttpd 或某种形式的负载平衡器),这也将为您提供https 终止。 - 这似乎是您对将请求转发到您的网站的 httprewrite 所做的。
您可能会发现一些廉价的 SSL 证书提供程序,它们安装在大多数浏览器中?
简答。不,没有没有方法来做到这一点。
与 https 的连接发生在之前发生任何类型的重定向。您唯一能做的就是购买证书。如今,常规域证书非常便宜。
您可以获得一个有效的域证书 4.99 美元/年。然后进行重定向,使 https 和 http 都被覆盖。
或者您可以关闭 443 虚拟主机,但用户将收到 404 或连接错误页面。如果他们尝试 https。
这些是你的选择。只要它是自签名的并且是设计使然,您的用户将始终获得 警告页面 。