与MAMP同时运行SSL和非SSL站点(4.0.6)

时间:2016-12-02 11:34:57

标签: apache ssl mamp virtualhost httpd.conf

要启用SSL,我在httpd.conf中取消注释了这一行:

# Secure (SSL/TLS) connections
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

httpd-ssl.conf文件本身我没有动过,并且在默认情况下希望看到它们的地方为自签名SSL证书创建了.crt和.key文件: / p>

SSLCertificateFile "/Applications/MAMP/conf/apache/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/server.key"

回到主httpd.conf,我为我想要使用SSL的网站创建了一个VirtualHost,并按照这样配置最终使其工作:

NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Users/jonnott/Documents/sslsite1.dev"
ServerName sslsite1.dev:443
ServerAlias www.sslsite1.dev
SSLEngine on
SSLCertificateFile "/Applications/MAMP/conf/apache/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/server.key"
</VirtualHost>

此SSL网站现在可以正常使用。

但是,我遇到的问题是,现在每当我尝试访问任何本地非SSL主机时,都会收到此错误:

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.

这些其他非SSL站点在httpd.conf中配置如下:

<VirtualHost *> 
DocumentRoot "/Users/jonnott/Documents/site2.dev"
ServerName site2.dev
ServerAlias www.site2.dev
</VirtualHost>

我错过了什么/做错了什么?

1 个答案:

答案 0 :(得分:2)

我想在阅读完这篇文章后我已经弄明白了:

http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#vhosts2

在我的VirtualHost指令开始之前,我在httpd.conf中需要这些:

public String toString(){
int endh = (getEndHour()==0 || getEndHour()==12) ? getEndHour() : getEndHour()%12;
String period = ((getEndHour() + duration) <12)? "AM" : "PM";
return String.format("%02d:%02d %s", endh, getEndHour(), period);
}

..然后每个VirtualHost都需要特定于端口:

NameVirtualHost *:80
NameVirtualHost *:443