gpt4 book ai didi

apache - 使用 MAMP (4.0.6) 同时运行 SSL 和非 SSL 站点

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:36 26 4
gpt4 key购买 nike

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

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

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

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>

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

最佳答案

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

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

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

NameVirtualHost *:80
NameVirtualHost *:443

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

<VirtualHost *:80>
DocumentRoot "/Users/jonnott/Documents/Projects/site1"
ServerName site1.dev:80
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/Users/jonnott/Documents/Projects/site1"
ServerName site1.dev:443
SSLEngine on
SSLCertificateFile "/Applications/MAMP/conf/apache/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/server.key"
</VirtualHost>

关于apache - 使用 MAMP (4.0.6) 同时运行 SSL 和非 SSL 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40931294/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com