简体   繁体   English

如何将Rails服务器设置为Apache?

[英]How to set Rails server to apache?

Since I was working on PHP + Apache + Mysql, and I was working with Ruby on Rails in different configuration I want to start my new project with cofiguration like this : Rails + Apache + Mysql. 由于我从事PHP + Apache + Mysql的工作,并且我以不同的配置使用Ruby on Rails,所以我想以这样的配置开始新项目:Rails + Apache + Mysql。 I already connected Rails project with mysql, but I dont know how to set Server to Apache. 我已经用MySQL连接了Rails项目,但是我不知道如何将Server设置为Apache。 rails server starts WEBrick all the time. rails服务器始终启动WEBrick。 What is the solution to set the apache server on? 设置apache服务器的解决方案是什么?

I recommend using nginx instead of apache. 我建议使用nginx而不是Apache。 If you really want to use apache you can look into passenger. 如果您真的想使用Apache,可以研究乘客。

or 要么

you can use the proxypassreverse module of apache 您可以使用apache的proxypassreverse模块

Module dependencies 模块依赖

  • mod_rewrite mod_rewrite的
  • mod_ssl mod_ssl
  • mod_proxy mod_proxy
  • mod_proxy_http mod_proxy_http

Your vhost could look somewhat like this 您的虚拟主机可能看起来像这样

<VirtualHost *:80>
ServerName gitlab.example.com

ProxyPreserveHost On

<Location />
  Order deny,allow
  Allow from all

  ProxyPassReverse http://127.0.0.1:3000/
  ProxyPassReverse http://example.com/
</Location>

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://127.0.0.1:3000%{REQUEST_URI} [P,QSA]
</VirtualHost>

You would have to change the port if your application run under another one 如果您的应用程序在另一端口下运行,则必须更改端口

Passenger is a rails container that can be installed as an apache module. 乘客是可以作为apache模块安装的滑轨容器。 Run the following two commands to install passenger: 运行以下两个命令来安装passenger:

gem install passenger
passenger-install-apache2-module

Then, just follow the instructions shown on the screen. 然后,只需按照屏幕上显示的说明进行操作。 In the end, you will be shown a sample VirtualHost . 最后,将显示一个示例VirtualHost Use that to adjust your actual VirtualHost settings 使用它来调整您的实际VirtualHost设置

You will also be shown 3 lines that pertain to loading passenger as an apache module. 您还将看到3行有关将乘客作为apache模块装载的信息。 Just copy paste those lines into your httpd.conf (or apache.conf as the case may be). 只需将这些行复制粘贴到您的httpd.conf(或apache.conf中,视情况而定)即可。

With this setup, you need not run WEBrick. 使用此设置,您无需运行WEBrick。 Passenger will automatically boot your rails application 乘客将自动启动您的rails应用程序

If you are also running PHP applications on the same apache instance, you can turn off passenger inside your PHP related VirtualHost using PassengerEnabled off directive 如果您也在同一apache实例上运行PHP应用程序,则可以使用PassengerEnabled off指令在与PHP相关的VirtualHost关闭passenger。

For more configuration options see Passenger Manual for Apache 有关更多配置选项,请参阅《 Apache乘客手册》

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM