gpt4 book ai didi

apache - 如何创建同时支持 http 和 https 的虚拟主机?

转载 作者:可可西里 更新时间:2023-11-01 15:08:27 25 4
gpt4 key购买 nike

我的配置是:

Listen 443 http
NameVirtualHost *:80
NameVirtualHost *:443
ServerName *:80

<VirtualHost *:80>
[some non-ssl stuff]
ServerName account.example.com
</VirtualHost>

<VirtualHost *:443>
[some non-ssl stuff(directory, docroot)]
ServerName account.example.com
SSLEngine on
SSLCertificateFile /Users/myusername/certs/server.crt
SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>

所以我无法访问我网站的 http 版本,但 ssl 版本工作正常。我想同时使用虚拟主机、http(80) 和 https(443) 通过 mod_rewrite 将 http 重写为 https URL。

uname -a
Linux 3.4.62-53.42.amzn1.x86_64 GNU/Linux

httpd -v
Server version: Apache/2.2.25 (Unix)

请帮助理解我做错了什么。

最佳答案

所以,我现在的配置是:

Listen 443 http
Listen 80
NameVirtualHost *:80
NameVirtualHost *:443
ServerName *:80

<VirtualHost *:443>
[some non-ssl stuff(directory, docroot)]
ServerName account.example.com
SSLEngine on
SSLCertificateFile /Users/myusername/certs/server.crt
SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>

<VirtualHost *:80>
SSLEngine off
[other stuff like docroot]
</VirtualHost>

不确定 SSLEngine off,但现在可以了。因此,我在 http vhost 的 .htaccess 文件中添加重写规则以从 http 重定向到 https:

#Redirrect from http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

关于apache - 如何创建同时支持 http 和 https 的虚拟主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852817/

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