【问题标题】:Redirect https request to internal http port将 https 请求重定向到内部 http 端口
【发布时间】:2021-12-27 13:53:11
【问题描述】:

我正在尝试设置一个域 (example.com),它将 HTTPS 请求重定向到 HTTP localhost:8545

我在apache上试过如下配置(第一次尝试监听8082端口)

<VirtualHost *:8082>
        ServerName example.com

        SSLProxyEngine on
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
                AddDefaultCharset Off
                Order deny,allow
                Allow from all
        </Proxy>
        ProxyPass / http://127.0.0.1:8545
        ProxyPassReverse / http://127.0.0.1:8545

        ErrorLog "/var/log/apache2/proxy-error.log"
        CustomLog "/var/log/apache2/proxy-access.log" common
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

第二次尝试在proxy_conf-ssl.conf上如下

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName example.com

        SSLProxyEngine on
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
                AddDefaultCharset Off
                Order deny,allow
                Allow from all
        </Proxy>
        ProxyPass / http://127.0.0.1:8545
        ProxyPassReverse / http://127.0.0.1:8545

        ErrorLog "/var/log/apache2/proxy-error.log"
        CustomLog "/var/log/apache2/proxy-access.log" common

SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

但这些似乎都没有正常工作。我需要实现的是能够从需要 HTTPS 连接的移动 Metamask 访问在 0.0.0.0:8545 上运行的本地 ganache 客户端

【问题讨论】:

    标签: https http-redirect metamask ganache


    【解决方案1】:

    经过几次尝试,我通过禁用来自 8082 的重定向和 443 上的 SSLProxyEngine 来修复它。所以配置如下:

    使用 SSL

    <IfModule mod_ssl.c>
    <VirtualHost *:443>
            ServerName example.com
    
    #       SSLProxyEngine on
            ProxyRequests Off
            ProxyPreserveHost On
            <Proxy *>
                    AddDefaultCharset Off
                    Order deny,allow
                    Allow from all
            </Proxy>
            ProxyPass / http://127.0.0.1:8545
            ProxyPassReverse / http://127.0.0.1:8545
    
            ErrorLog "/var/log/apache2/proxy-error.log"
            CustomLog "/var/log/apache2/proxy-access.log" common
    
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
    </IfModule>
    

    没有SSL

    <VirtualHost *:8082>
            ServerName example.com
    
            SSLProxyEngine on
            ProxyRequests Off
            ProxyPreserveHost On
            <Proxy *>
                    AddDefaultCharset Off
                    Order deny,allow
                    Allow from all
            </Proxy>
            ProxyPass / http://127.0.0.1:8545
            ProxyPassReverse / http://127.0.0.1:8545
    
            ErrorLog "/var/log/apache2/proxy-error.log"
            CustomLog "/var/log/apache2/proxy-access.log" common
    #RewriteEngine on
    #RewriteCond %{SERVER_NAME} =example.com
    #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 2018-08-23
      • 2012-06-19
      • 2019-07-28
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多