Apache 阻塞(不是简单地重写或重定向)标准 http 请求

Apache blocking (not simply rewriting or redirecting) standard http request

我有一个带有特定路径的站点,我正试图将其用作另一个软件的下载存储库。因为这个网站是分发给第三方使用的,所以我不能依赖这个网站的证书是合法的(第三方可以安装他们自己的证书)我需要通过 http 而不是 https 访问这个存储库,否则我的安装软件会停止并且不安装文件,因为它不信任该站点。我目前一直在使用 Apaches RewriteEngine 强制所有 http 请求到 https。我用以下内容更新了它的配置:

<VirtualHost _default_:80>

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule !.*/path/to/repo/.* https://%{HTTP_HOST}%{REQUEST_URI} 

<VirtualHost>

</VirtualHost _default_:*>

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule .*/path/to/repo/.* http://%{HTTP_HOST}%{REQUEST_URI}

# More configuration down here.
</VirtualHost>

但是当我尝试访问 http://www.example.net/path/to/repo/ 时,它只是立即给我一个未找到的错误

我进一步深入研究并完全删除了从 http 到 https 的重写,发现如果我尝试使用标准 http

我根本无法访问我网站的任何页面

这是一个 Django 网站,所以我查看了我的设置文件,看看里面是否有什么东西会阻止它接受 http,但没有发现任何明显的东西。是否有我应该检查的其他设置(可能在 apache 的配置中)以查看标准 http 是否已被禁用?

问题正如我在上面的评论中所怀疑的那样。因为只为端口 80 定义了一个明确的 VirtualHost,所以任何通过重定向过滤器(以前过滤所有内容)的东西都会被置若罔闻,因为没有主机设置来监听这些请求。

为了解决这个问题,我必须定义一个进程来接受这些连接。

这是更完整的代码版本,包括我为修复它所做的工作:

<VirtualHost _default_:80>
# redirecting all but repo requests to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule !.*/path/to/repo/.* https://%{HTTP_HOST}%{REQUEST_URI}

CustomLog /var/log/apache2/repo-host.access.log combined

WSGIDaemonProcess repo-host user=admin group=repo-host processes=2 threads=2 maximum-requests=1500 inactivity-timeout=60 deadlock-timeout=45
WSGIProcessGroup repo-host
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /path/to/appliance.wsgi
WSGIPassAuthorization on

SSLEngine off
</VirtualHost>


<IfModule mod_ssl.c>
<VirtualHost _default_:*>
# redirecting https requests to the repo back to http
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule .*/path/to/repo/.* http://%{HTTP_HOST}%{REQUEST_URI}

CustomLog /var/log/apache2/ssl-host.access.log combined

WSGIDaemonProcess ssl-host user=admin group=ssl-host processes=5 threads=5 maximum-requests=1500 inactivity-timeout=60 deadlock-timeout=45
WSGIProcessGroup ssl-host
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /path/to/appliance.wsgi
WSGIPassAuthorization on

SSLEngine on
SSLCertificateFile    /path/to/ssl-cert.pem
SSLCertificateKeyFile /path/to/ssl-cert.key

</VirtualHost>

如果有更好的解决方法,请在下方评论或提交您自己的答案让我知道。谢谢