multiple rails app in apache using passenger on centos - ruby-on-rails

I have been following this guide on how to run a rails app in an apache server. I have successfully made it work but with only 1 rails app running. I tried editing the httpd.conf with 2 virtual hosts.
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.42
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.1.1/ruby
RackEnv development
<VirtualHost *:3000>
ServerName ***.***.***.***
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/testapp/public
<Directory /var/www/html/testapp/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:3001>
ServerName ***.***.***.***
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/testapp2/public
<Directory /var/www/html/testapp2/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
but it seems only port 3000 is working.

You'll need to make sure you have the other server set up on port 3001
Port
The problem you'll have is that you're capturing the same request (to same domain / IP), except listening on different ports. If you want to access the different sites, therefore, you have to access by the ports you define.
#app1 -> ***.***.***.***:3000
#app2 -> ***.***.***.***:3001
This should give you the ability to access your Rails apps respective to your apache implementation.
--
VirtualHosts
If I were you, I'd either create a virtualhost with a directory setup:
/etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName [ip]
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /apps/public
#Other App
Alias /app1 /apps/app1/public
<Location /reach>
PassengerAppRoot /apps/app1/public
RackEnv production
RackBaseURI /app1
</Location>
#Other App
Alias /app2 /apps/app2/public
<Location /apps>
PassengerAppRoot /apps/app2/public
RackEnv production
RackBaseURI /app2
PassengerFriendlyErrorPages off
</Location>
</VirtualHost>
This will give you a much simpler way to handle the incoming requests:
***.***.***.*** -> IP index
***.***.***.***/app1 -> application 1
***.***.***.***/app2 -> application 2
I'd be much more tempted to use the above setup than your own.
Further, you may also wish to actually deploy separate virtual hosts for your applications. The above example details how you'd introduce different directories for your different apps - if you'd prefer to create different virtualhosts, here's what you can do:
#etc/apache2/sites-available/default (standard site - I'd recommend static)
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
#etc/apache2/sites-available/app1
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias yourdomain.com
DocumentRoot /apps/app1/public
<Directory /apps/app1/public>
Allow from all
Options -MultiViews
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Don't forget to symlink these to your /etc/apache2/sites-enabled folder:
> $ ln -s /etc/apache2/sites-available/app1 /etc/apache2/sites-enabled/app1

Related

How to config Sails/Node App with Apache/Passenger

First of all, this is for dev purposes only. On my Mac I've got Apache running with Passenger which serve many Rails/Ruby App. An example of an Apach config for Rails would be:
<VirtualHost *:80>
ServerName example.lc
ServerAlias www.example.lc
RailsEnv development
PassengerFriendlyErrorPages on
PassengerRuby /Users/user/.rvm/gems/ruby-2.2.3/wrappers/ruby
DocumentRoot "/path/to/my/app/public"
ErrorLog "/path/to/my/app/log"
CustomLog "/path/to/my/app/log" common
ServerAdmin example#example.com
<Directory "/path/to/my/app/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And on my host file I'd have 192.168.0.1 www.example.lc and that would work fine.
I'd like to do the same for a Node App based off Sails. I've tried the following:
<VirtualHost *:80>
ServerName example.lc
ServerAlias www.example.lc
NODE_ENV development
PassengerFriendlyErrorPages on
PassengerNodejs /usr/bin/node
DocumentRoot "/path/to/my/app/public"
ErrorLog "/path/to/my/app/log"
CustomLog "path/to/my/app/log" common
ServerAdmin me#example.com
<Directory "/path/to/my/app/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
But that doesn't work. Nor it shows any error on the log file. Any ideas?
Please note that I've also tried PassengerNodejs /Users/user/.nvm/versions/node/v4.4.7/bin/node which is the path I get when I do which node. That didn't work either.

Apache VirtualHosts for a Rails app

On a server there is already a site running. I'm trying to make my rails app run on a url of the same site i.e the site is example.com and the rails app will run at example.com/railsapp.
The rails app will use passenger and the server is ubuntu.
The current virtualhosts file looks like;
<VirtualHost *:80>
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /var/www/examplesite/>
Options Indexes FollowSymlinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Do I need to add a separate hosts file?
<VirtualHost *:80>
ServerName ???
DocumentRoot /var/www/railsapp/public
<Directory /var/www/railsapp/public>
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
I'm not sure what to do...
The proper solution is documented in the Deploying to a sub URI Passenger documentation:
Suppose that you already have a virtual host:
<VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
</VirtualHost>
And you want your Rails application, located in /websites/rails, to be accessible from the URL http://www.phusion.nl/subapp.
To do this, you need to perform the following:
Set Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}.
Create a <Location /{SUBURI}> block.
Inside the Location block, set PassengerBaseURI /{SUBURI}.
Inside the Location block, set PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}.
Create a <Directory {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}> block.
Inside the Directory block, set Allow from all.
Inside the Directory block, disable MultiViews.
Here is an example:
<VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion
<Directory /websites/phusion>
Allow from all
</Directory>
# These have been added:
Alias /subapp /websites/rails/public
<Location /subapp>
PassengerBaseURI /subapp
PassengerAppRoot /websites/rails
</Location>
<Directory /websites/rails/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

Passenger always shows "Index of"

I've been sticking with this problem for a week. I cannot get my Rails application running via passenger module of Apache2. I use Ubuntu 12.04 64-bit with Rails 3.2.8 Ruby 1.9.3 Passenger 4.0.5.
My Rails apps is at /home/sarunint/cafe_grader/web
This is my /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
RailsBaseURI /grader
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
And this is my /etc/apache2/httpd.conf
LoadModule passenger_module /home/sarunint/.rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
PassengerRoot /home/sarunint/.rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.5
PassengerRuby /home/sarunint/.rvm/wrappers/ruby-1.9.3-p392/ruby
PS. If this is a duplicated topic, feel free to tell me :)
Thanks
Update
I've just noticed that when I restart Apache2 I got this :
sarunint#server1:~$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2
[Tue Jun 18 23:05:56 2013] [warn] module passenger_module is already loaded, skipping
... waiting [Tue Jun 18 23:05:57 2013] [warn] module passenger_module is already loaded, skipping
Update 2
After doing some grep's by #mohamed-abshir, I got these lines :
sarunint#server1:/etc/apache2$ grep -irl "LoadModule passenger_module" .
./mods-available/passenger.load
./mods-enabled/passenger.load
./httpd.conf
Thanks.
Update 3
which ruby prints this :
/home/sarunint/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
cat /etc/apache2/mods-enabled/passenger.load prints this :
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
and this is the file you want :
<VirtualHost *:80>
ServerName sarunint.uni.me
ServerAdmin webmaster#localhost
DocumentRoot /var/www
RailsBaseURI /grader
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
<Directory /home/sarunint/cafe_grader/web/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Since passenger 2.0 it's not following symlinks for DocumentRoot, the way passenger detects if its a ruby on rails application is looking for a config.ru one level behind the DocumentRoot directory. Suppose DocumentRoot is /var/www/public, it will search in /var/www for a config.ru file. But if www is a symlink to another location, let's say /var/www -> /home/ruby/my_app/public it will not follow the sym links so wouldn't be able to find the file and will not process the request.
To fix this, you can add to the httpd.conf:
PassengerResolveSymlinksInDocumentRoot on
If your sitename is "example.com" then under ServerAdmin webmaster#localhost line, you need:
ServerName example.com
ServerAlias www.example.com #not necessary
DocumentRoot should point to your site files and become:
DocumentRoot home/sarunint/cafe_grader/web/public
Your Directory block should be:
<Directory /home/sarunint/cafe_grader/web/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Then restart apache and go to your site url.
I haven't checked your Ruby pointers, but basically on commandline when do "which ruby" the location that gets printed out, should match your what you posted above as your ruby interpreter.
Update
The op posted a note about passenger module being loaded again.
When Passenger is installed normally via rvm, it tells you what commands to run and where to put the 3 lines of code that you posted above(they normally go under conf.d/passenger.conf). It appears there is "Passenger module is loaded twice" so go to your Apache directory search for it like:
cd /etc/apache2/
grep -irl "LoadModule passenger_module" . # this searchs those words in current dir(don't remove the dot = current dir"
<VirtualHost *:80>
#this isn't working, it's running under drew
PassengerDefaultUser www-data
ServerAdmin youremail#mail.com
ServerName mysite.localhost.com
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
DocumentRoot /var/www/rails/ridcyDevelopment/public
RailsEnv development
#RailsBaseURI /
<Directory /var/www/rails>
Options Indexes FollowSymLinks -MultiViews +ExecCGI
AllowOverride all
Allow from All
</Directory>

GitLab + apache + Phusion Passenger -> No such file or directory - config/environment.rb

I'm installing Gitlab using the official manual https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md but I don't want to use ngix, instead I'm using apache with passenger. I must admit that I'm still a linux newbie.
Anyway, here's the error:
Error message: No such file or directory - config/environment.rb
And here's my apache config:
ServerAdmin webmaster#localhost
DocumentRoot /var/www
RailsBaseURI /gitlab
RackBaseURI /gitlab
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/gitlab>
Options -MultiViews
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Any ideas what I'm doing wrong?
You're not supposed to have this in your config:
RailsBaseURI /gitlab
RackBaseURI /gitlab
As explained in the Phusion Passenger documentation, "RailsBaseURI" says "I have a Rails 2 app under that URI". Gitlab is a Rails 3 app, so you need "RackBaseURI". But you specified both, and "RailsBaseURI" has precendence, so Phusion Passenger thinks /gitlab is a Rails 2 app.
Get rid of "RailsBaseURI" and you should be fine.
Hmm most likely one of
DocumentRoot /var/www
RailsBaseURI /gitlab
RackBaseURI /gitlab
is simply pointing to the wrong directory. To which directory have you checked out the gitlab code? Does it match the values?
Btw I am using pretty much the same setup as you to run gitlab (apache+passenger) and have only DocumentRoot set.
For your reference, here is my virtual host config, Maybe it helps you:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName git.your_server_address
PassengerMinInstances 1
DocumentRoot /home/gitlab/gitlab/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

symfony can't call any module. config?

I set up another computer (Linux Mint 12). I can call in a browser the index of my project very well with and without frontend_dev.php. But I can not call any module. It is saying the file does not exist. Any idea?
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
ServerAlias dev.project.com
DocumentRoot /home/trunk/web
DirectoryIndex index.php index.html index.htm
Alias /sf "/home/trunk/symfony/data/web/sf"
<Directory /home/trunk/web>
AllowOverride All
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
<Directory /home/trunk/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory /home/trunk/symfony">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Based on comments above, the problem lies your webserver. I would check that:
Your Apache config is set to allow Path Info stuff (AcceptPathInfo is set to something other than Off). Try On if it's set to Default
Your Apache config is set to allow .htaccess files (check the AllowOverride is not set to None and AccessFileName is set to .htaccess)
You have mod_rewrite enabled in your Apache build (try removing the <IfModule mod_rewrite.c> and </IfModule> bits from your .htaccess. If mod_rewrite doesn't exist, Apache will throw a 500 error)
Are you using Apache as web server ?
Did you setup it as the doc says ?
And what about the .htaccess ?

Resources