Apache 为什么以下代理不绕过X-Frame-Options标头?

Apache 为什么以下代理不绕过X-Frame-Options标头?,apache,iframe,reverse-proxy,x-frame-options,Apache,Iframe,Reverse Proxy,X Frame Options,我需要在iframe中显示一些站点,但我不能直接这样做,因为其中一些站点的标题X-Frame-Options设置为“SAMEORIGIN”。为了绕过这个问题,我尝试在apache中使用反向代理。下面是我的apache配置 <VirtualHost *:80> ServerName google.local ProxyRequests Off DocumentRoot /var/www/html/iframe-test ProxyPass /test http://www.orac

我需要在iframe中显示一些站点,但我不能直接这样做,因为其中一些站点的标题X-Frame-Options设置为“SAMEORIGIN”。为了绕过这个问题,我尝试在apache中使用反向代理。下面是我的apache配置

<VirtualHost *:80>
ServerName google.local
ProxyRequests Off

DocumentRoot /var/www/html/iframe-test

ProxyPass /test http://www.oracle.com/index.html
ProxyPassReverse /test http://www.oracle.com/index.html

ErrorLog /var/log/apache2/google.local-error.log
CustomLog /var/log/apache2/google.local-access.log combined

<Location *>
    AllowOverride All
    Order allow,deny
    Allow from all
    # Header always append X-Frame-Options "ALLOW-FROM all"
    Header add test-header 'test'
</Location>

ServerName google.local
代理请求关闭
DocumentRoot/var/www/html/iframe测试
代理通过/测试http://www.oracle.com/index.html
ProxyPassReverse/测试http://www.oracle.com/index.html
ErrorLog/var/log/apache2/google.local-error.log
CustomLog/var/log/apache2/google.local-access.log组合
允许超越所有
命令允许,拒绝
通融
#标题始终附加X-Frame-Options“ALLOW-FROM all”
标题添加测试标题“测试”


但我仍然无法在iframe中加载站点,并且我收到错误
加载被X-Frame-Options拒绝:https://www.oracle.com/index.html 不允许跨源帧。

上述配置的问题是代理仅适用于http协议。但正如控制台错误消息所示,外部站点实际上会自动将http重定向到https。
因此,为了处理https请求,需要在apache中启用ssl并启用SSLProxyEngine。为此,

  • 在终端上运行
    sudo a2enmod ssl
  • 将行“SSLProxyEngine On”添加到上述配置中

    <VirtualHost *:80>
        ServerName google.local
    
        ProxyRequests On
        ProxyPreserveHost Off
        SSLProxyEngine On
    
        DocumentRoot /var/www/html/iframe-test
    
        ProxyPass /test http://www.oracle.com/index.html
        ProxyPassReverse /test http://www.oracle.com/index.html
    
        ErrorLog /var/log/apache2/google.local-error.log
        CustomLog /var/log/apache2/google.local-access.log combined
    
        <Location *>
            AllowOverride All
            Order allow,deny
            Allow from all
            # Header always append X-Frame-Options "ALLOW-FROM all"
            Header add test-header 'test'
        </Location>
    </VirtualHost>
    
    
    ServerName google.local
    代理请求
    代理主机关闭
    SSLProxyEngine打开
    DocumentRoot/var/www/html/iframe测试
    代理通过/测试http://www.oracle.com/index.html
    ProxyPassReverse/测试http://www.oracle.com/index.html
    ErrorLog/var/log/apache2/google.local-error.log
    CustomLog/var/log/apache2/google.local-access.log组合
    允许超越所有
    命令允许,拒绝
    通融
    #标题始终附加X-Frame-Options“ALLOW-FROM all”
    标题添加测试标题“测试”