在单个端口上都有ssl和non-ssl

我想让我的apache2 web服务器在同一个端口上同时提供http和https。
用不同的方法,我试过它要么不工作在http或https上..

我怎样才能做到这一点?

更新:
如果我启用SSL,然后访问与http我得到这样的页面:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> Reason: You're speaking plain HTTP to an SSL-enabled server port.<br /> Instead use the HTTPS scheme to access this URL, please.<br /> <blockquote>Hint: <a href="https://server/"><b>https://server/</b></a></blockquote></p> <hr> <address>Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny16 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g Server at server Port 443</address> </body></html> 

正因为如此,看起来很有可能在同一个端口上同时使用http和https。
第一步是改变这个默认页面,所以它会呈现301-Moved标题。

Update2:据此,这是可能的。 现在,问题是如何configurationApache来做到这一点。

SSLstream量不能在非SSLstream量的同一端口上工作,TLS可以这样做,但不能在Web服务器上使用TLS最常用于SMTP服务器,因为这个原因

同样的问题已经被不同的人问了好几次了(下面有两个例子),总是说,单独使用Apache是​​不可能的,你将不得不使用一些其他的软件或者自己创build一个类似的监听器:

Apache2将端口5553上的http重写为https

Apache在同一个端口上同时回答HTTP和HTTPS

另外我找不到任何正式的Apache文档,在没有redirect的情况下在相同的端口上提到http和httpsstream量。

请记住,当人们说SSL时,他们通常认为SSL / TLS是不一样的。

我会从apache.org采取这个答案作为一个明确的NO到您的问题与http和https在同一端口上工作

  Can we have both http and https listening on the same port? Comment 1 Eric Covener 2011-11-22 14:36:45 UTC No, and bugzilla is not for support or Q&A. Try the users mailing list. 

https://issues.apache.org/bugzilla/show_bug.cgi?id=52228

你可以试试mod_rewrite模块,但是我build议你打开另外一个关于如何使用httpsredirect的问题(你仍然需要有多个端口)。 我没有与它合作,所以不能告诉你如何做的细节。

就像我说的,对模块不太了解,所以我的猜测是你需要三个端口。 一个用于mod_rewrite侦听的非SSL端口,一个用于httpstream量的非SSL和一个用于https的SSL端口,您必须为mod_rewrite创build999端口,然后让您的服务在http和https的两个不同端口上侦听。

注意Shane Madden在他的评论中所说的话,即使你把mod_rewrite放在那个端口上,启用SSL的端口上的http请求也只会给你错误。

可以使用自定义的ErrorDocument将httpredirect到https。
尽pipe在Apache和Apache上运行整个Web服务器是不可能的。

不幸的是,Apache 2.2-16中存在一个bug,这个bug还没有被修复,因为redirect只能在Apache 2.4中运行。

更多信息请看这里: https : //issues.apache.org/bugzilla/show_bug.cgi?id=50823

更新
这里是我用apache 2.4testing的一个概念validation片段:

 <?php if ($_SERVER["REDIRECT_STATUS"] == "400" && preg_match("/.*?Reason: You're speaking plain HTTP to an SSL-enabled server port\..*/", $_SERVER["REDIRECT_ERROR_NOTES"])) { header("Location: https://localhost:999"); } else { //echo normal error message } ?> 

通过在你的apacheconfiguration文件中设置ErrorDocument 400 /redirect-400-error.php来使用它。 你可以在这里find更多关于自定义ErrorDocuments的信息。

简单解决scheme

 ErrorDocument 400 https://server:port/ 

现在你得到一个“find”的redirect,并没有讨厌的错误消息。

我认为这可以通过定义一个静态的ErrorDocument,例如:

ErrorDocument 400 /redirect_https.txt

然后使用以下内容在文档根目录中创build文件redirect_https.txt

 HTTP/1.1 302 Found Location: https://www.example.com/mypage.html 

这工作(甚至尝试),并发送浏览器一个“假的”HTTPredirect。