将https请求重定向到内部http端口



我正在尝试设置一个域(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-sl.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客户端

经过几次尝试后,我通过禁用8082和443上的SSLProxy引擎的重定向来修复它。因此配置如下:

使用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>

最新更新