使用Apache HTTPD代理的Rails / Puma?

时间:2015-04-01 20:25:14

标签: ruby-on-rails apache puma

我想使用Puma和HTTPD来为我的Rails应用程序提供服务。据我所知,人们做这种事情的例子并不多。我知道nginx比HTTPD有一些好处,而且Passenger使很多事情变得简单,但有没有理由使用Puma / HTTPD?

我已经在网上浏览了几个例子并整理了一个我喜欢的HTTPD配置块,这似乎工作得很好(尽管我还没有进行任何性能测试)。我错过了什么吗?这似乎比大多数Puma / nginx或Passenger / HTTPD设置更简单/更简单,这让我有点担心。

<VirtualHost *:3008>
  DocumentRoot MY_RAILS_ROOT/public
  ProxyPass /favicon.ico !
  ProxyPass /robots.txt !
  ProxyPassMatch ^/(404|422|500).html$ !
  ProxyPass /assets/ !

  ProxyPass / http://127.0.0.1:9292/ # Puma bind address
  ProxyPassReverse / http://127.0.0.1:9292/
</VirtualHost>

1 个答案:

答案 0 :(得分:2)

这是Apache HTTPD作为反向代理的相当常见的用法,因此没有特别的问题。你在同一台机器上运行Web服务器和puma吗?将它们拆分以防止内存消耗,TCP堆栈以及高负载下可能发生的任何其他争用的问题可能是个好主意。

如果您有多个puma节点,那么您可以使用HTTPD在所有节点上执行负载平衡,如下所示:

<VirtualHost example.org:80>
    ServerName example.org
    ServerAlias www.example.org

    ErrorLog /srv/www/example.org/logs/error.log 
    CustomLog /srv/www/example.org/logs/access.log combined

    DocumentRoot MY_RAILS_ROOT/public

    <Proxy balancer://cluster>
        BalancerMember http://app1.example.org
        BalancerMember http://app2.example.org
    </Proxy>

    ProxyPass /favicon.ico !
    ProxyPass /robots.txt !
    ProxyPassMatch ^/(404|422|500).html$ !
    ProxyPass /assets/ !

    ProxyPass / balancer://cluster/
    # enumerate all nodes for proxypassreverse since it adds a trailing slash :( bugid 51982
    ProxyPassReverse / http://app1.example.org
    ProxyPassReverse / http://app2.example.org


    # ProxyPass / balancer://cluster/ lbmethod=byrequests
    # ProxyPass / balancer://cluster/ lbmethod=bytraffic
    # ProxyPass / balancer://cluster/ lbmethod=bybusyness
</VirtualHost>

虽然如果您有更好的HA选项(即AWS ELB,HAProxy,Varnish或其他任何东西),那么我希望您免费获得第7层可用性检查