为什么下面的代理没有绕过X-Frame-Optionsheader?

Why following proxy does not bypass X-Frame-Options header?

我需要在 iframe 中显示一些网站,但我不能直接这样做,因为其中一些网站的 header 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>

但我仍然无法在 iframe 中加载网站,并且出现错误 Load denied by X-Frame-Options: https://www.oracle.com/index.html does not permit cross-origin framing.

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

  1. 运行 sudo a2enmod ssl 在终端上
  2. 将行'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>