【问题标题】:apache http: redirect to https:apache http:重定向到 https:
【发布时间】:2016-02-04 02:27:42
【问题描述】:

我正在尝试将我的 apache 服务器配置为在用户浏览到 http:// url 时重定向到 https://

我在谷歌上搜索过,但事情并不完全奏效。这是我尝试过的:

Listen 443
….
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile "/usr/local/apache2/conf/server.crt"
    SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

    SSLProxyEngine On
    ServerAdmin webmaster@localhost
    DocumentRoot /usr/local/apache2/htdocs
</VirtualHost>

ErrorLog /usr/local/apache2/logs/error.log
CustomLog /usr/local/apache2/logs/access.log combined

FallbackResource /index.html

使用此配置,这是浏览器的响应:

################## 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.

另外,我试过这个:

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile "/usr/local/apache2/conf/server.crt"
    SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

    SSLProxyEngine On
    ServerAdmin webmaster@localhost
    DocumentRoot /usr/local/apache2/htdocs

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

但无济于事(相同的浏览器响应)。

我做错了什么?

谢谢

【问题讨论】:

  • 进行更改时是否要重新启动 Apache?此外,在测试重定向之前,首先检查您是否拥有正确的 https 也是值得的。你能浏览到https url吗?

标签: apache ssl httpd.conf


【解决方案1】:

看第二个例子,我想说重写部分应该进入标准主机,*:80...

另外,错误消息可能来自没有准备好至少能够通过 http 传递重定向的服务器...

【讨论】:

    猜你喜欢
    • 2013-09-27
    • 2016-01-17
    • 2018-04-09
    • 2019-11-08
    • 2018-08-25
    • 2019-12-17
    • 2022-01-06
    • 2016-04-16
    • 2015-02-03
    相关资源
    最近更新 更多