【问题标题】:Chef API server behind Apache reverse HTTP proxy returns http instead of https linksApache 反向 HTTP 代理后面的 Chef API 服务器返回 http 而不是 https 链接
【发布时间】:2012-01-30 22:46:17
【问题描述】:

我有一个在机器上运行的厨师服务器(侦听端口 4000),我想通过 SSL 访问它。我已经设置了一个 Apache 反向代理来执行此操作(侦听端口 4001)。 Apache 设置看起来像(我的机器名称替换为 www.example.com)

Listen 4001

<VirtualHost *:4001>

   SSLEngine on
   SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
   SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

   ProxyRequests     Off
   ProxyPreserveHost On

   <Proxy http://localhost:4000*>
     Order deny,allow
     Allow from all
   </Proxy>

   ProxyPass         /  http://localhost:4000/
   ProxyPassReverse  /  http://localhost:4000/
   ProxyPassReverse  /  http://www.example.com:4000/
   ProxyPassReverse  /  http://www.example.com:4001/

   CustomLog ${APACHE_LOG_DIR}/chef.access.log common
   ErrorLog ${APACHE_LOG_DIR}/chef.error.log

</VirtualHost> 

问题在于 Chef API 调用返回的 JSON 中的 URL 具有 http 而不是 https。例如,它们看起来像:

http://www.example.com:4001/sandboxes/a25fa2615d3d4dbd91e91a5e3a76c0ea

代替:

https://www.example.com:4001/sandboxes/a25fa2615d3d4dbd91e91a5e3a76c0ea

一个例子是在对/sandboxes 进行 POST 以创建一个新沙箱时,该沙箱创建了上面的链接。这会破坏诸如尝试使用刀上传食谱之类的事情。

据我所知,/sandboxes POST 调用的主厨服务器 create method 调用了 Merb absolute_url 辅助方法来生成 URL。

此时,我对如何解决此问题感到困惑。我是否需要以某种方式更改我的 Apache 反向代理配置?它是厨师服务器中的配置选项吗?还是别的什么?

【问题讨论】:

    标签: ruby apache chef-infra merb


    【解决方案1】:

    我想你只需要添加:

    RequestHeader set X-Forwarded-Proto "https"
    

    到您的 Apache 配置。

    这会使 Apache 将 X-Forwarder-Proto: https 标头添加到对 Chef/Merb 服务器的所有请求中。在决定是否应将请求视为安全请求时,Merb 会检查此标头(您可以按照从 absolute_urlrequest#protocolrequest#ssl? 的请求从 options[:protocol] ||= request.protocol 开始)。

    ProxyPassReverse 指令仅更改后端的标头,它不会更改任何内容(这需要解析和识别内容中的 url)。传递此标头可以让 Merb 知道它应该像请求使用 SSL 一样行事,并根据需要创建链接。

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 2017-07-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      • 2020-04-04
      • 2017-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多