【问题标题】:Proxy not redirecting代理不重定向
【发布时间】:2021-01-10 05:17:39
【问题描述】:

我有以下 Apache 配置文件。当有人输入 http://mywebsite.com 时,它不会将他们重定向到 https。为什么?

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass "/" "http://10.0.1.123/"
    ProxyPassReverse "/" "http://10.0.1.123/"
    ServerName www.mywebsite.com
    ServerAlias mywebsite.com
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =mywebsite.com
    RewriteCond %{SERVER_NAME} =www.mywebsite.com
    RewriteRule ^ https://mywebsite.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLProxyEngine on
    ProxyPreserveHost On
    ProxyPass "/" "http://10.0.1.123:80/"
    ProxyPassReverse "/" "http://10.0.1.123:80/"
    ServerName www.mywebsite.com
    ServerAlias mywebsite.com
    ServerAdmin admin_ws1@mywebsite.com
    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/www.mywebsite.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.mywebsite.com/privkey.pem
</VirtualHost>

【问题讨论】:

    标签: apache ssl redirect proxy


    【解决方案1】:
    <VirtualHost *:80>
        ... 
        ProxyPass "/" "http://10.0.1.123/"
        ...
        RewriteRule ^ https://mywebsite.com%{REQUEST_URI} [END,NE,R=permanent]
    

    ProxyPass 告诉 Apache 充当反向代理并将请求转发到真实服务器。 RewriteRule 告诉 Apache 通过重定向到站点的 HTTPS 版本来回答请求本身。显然它不能同时做这两个,所以有冲突。请移除Proxy* 规则,只保留端口80 上的Rewrite* 规则。

    【讨论】:

    • 非常感谢。听起来很明显,你已经解释过了;)
    猜你喜欢
    • 2019-05-23
    • 2019-03-12
    • 2020-05-31
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 2015-05-28
    • 2019-03-11
    • 2017-04-09
    相关资源
    最近更新 更多