如何使用 passenger 将 Apache 连接到我在 Rails 实例上的 运行 Ruby?

How do I connect Apache to my running Ruby on Rails instance using passenger?

我在 Mac Sierra 上使用 Apache 2.4 和 Rails 5。我做到了

brew install passenger

然后我创建了这个文件

localhost:apache2 davea$ cat /etc/apache2/other/passenger.conf
LoadModule passenger_module  /usr/local/opt/passenger/libexec/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini
PassengerDefaultRuby /usr/bin/ruby

但是重启Apache后

sudo apachectl restart

然后启动我的 Rails 服务器(在端口 3000 上运行),我在我的机器上访问本地 url

https://mylocalurl.com/

而且我仍然看到我的 Apache 页面,而不是我的 Rails 页面。我还缺少什么可以将 Apache 连接到 Rails?

您需要在 apache 中配置一个虚拟主机,然后 Passenger 会为您启动您的 rails 应用程序(使用 apache 集成时您不会启动 rails 服务器)。

您至少需要将 apache 虚拟主机的文档根目录指向 rails 应用程序中的 public 目录。

<VirtualHost *:80>
    ServerName yourserver.com
    DocumentRoot /path/to/myapp/public

    <Directory /path/to/myapp/public>
        Allow from all
        Options -MultiViews
        Require all granted
    </Directory>
</VirtualHost>

进一步阅读:

https://www.phusionpassenger.com/library/config/apache/intro.html https://www.phusionpassenger.com/library/config/apache/reference/