简体   繁体   中英

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. I already connected Rails project with mysql, but I dont know how to set Server to Apache. rails server starts WEBrick all the time. What is the solution to set the apache server on?

I recommend using nginx instead of apache. If you really want to use apache you can look into passenger.

or

you can use the proxypassreverse module of apache

Module dependencies

  • mod_rewrite
  • mod_ssl
  • mod_proxy
  • 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. Run the following two commands to install 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 . Use that to adjust your actual VirtualHost settings

You will also be shown 3 lines that pertain to loading passenger as an apache module. Just copy paste those lines into your httpd.conf (or apache.conf as the case may be).

With this setup, you need not run WEBrick. Passenger will automatically boot your rails application

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

For more configuration options see Passenger Manual for Apache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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