How to config Sails/Node App with Apache/Passenger - ruby-on-rails

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.

Related

multiple rails app in apache using passenger on centos

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

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>

How to deploy Rails app on subdomain root with Apache and Passenger

I have working Rails app on sub-uri redmine.example.org/redmine and I want it on redmine.example.org
/var/www/work/redmine.src is approot
/var/www/work/redmine is symlink to /var/www/work/redmine.src/public
<VirtualHost *:80>
DocumentRoot /var/www/work
ServerName redmine.example.org
ErrorLog /var/log/apache2/redmine-error_log
CustomLog /var/log/apache2/redmine-access_log combined
<Directory /var/www/work/redmine>
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
</Directory>
RackBaseURI /redmine
<Directory /var/www/work/redmine.src>
Options -MultiViews
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I tried many combination and googled hours, but nothing works.
How should I change this config to deploy redmine on subdomain root?
Thanks in advance.
Well, it was easier, than I supposed.
When I read the manual again and again I found solution:
link to manual
Now my config file looks like this:
<VirtualHost *:80>
DocumentRoot /var/www/work/redmine.src/public
ServerName redmine.example.org
<Directory /var/www/work/redmine.src/public>
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Another way to deploy sub-uri app, might work for you too:
<VirtualHost *:80>
ProxyPass /sub_uri/ http://localhost:8000/sub_uri/
DocumentRoot /main_app/public
<Directory /main_app/public>
...
</Directory>
</VirtualHost>
<VirtualHost *:8000>
DocumentRoot /sub_uri/public
<Directory /sub_uri/public>
...
SetEnv RAILS_RELATIVE_URL_ROOT /sub_uri
</Directory>
</VirtualHost>
I installed Redmine 3.3.1 on a Debian 9.0 Stretch server using the packages provided by the distribution itself (Apache + Redmine + Ruby + Rails + Passenger + MariaDB) more or less following those guides:
http://www.redmine.org/projects/redmine/wiki/RedmineInstall
http://www.redmine.org/projects/redmine/wiki/InstallRedmineOnDebianStableApacheMysqlPassenger
I would like to leave www.example.org "for Apache" and redmine.example.org "for Redmine", so I ended up with the following setup.
I left /etc/apache2/sites-available/000-default.conf untouched and created a file named redmine.conf inside that same folder:
<VirtualHost *:80>
ServerName redmine.example.org
DocumentRoot /usr/share/redmine/public
PassengerRuby /usr/bin/ruby
<Directory /usr/share/redmine/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Then, I've linked it to the sites-enabled folder and restarted Apache:
# ln -s /etc/apache2/sites-available/redmine.conf /etc/apache2/sites-enabled/redmine.conf
# systemctl restart apache2
To set up that virtual host, I followed the directions here:
Deploying a Ruby application on Passenger + Apache
Deploying an app to a virtual host's root
https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/#deploying-an-app-to-a-virtual-host-s-root

Running Rails on Apache2

I have a linode server and was running a single website for dev purposes using webrick, now i want to put it into production and use Apache2 which I have installed and is up and running the classic It Work's! page which is expected.
Now I want to run multiple sites on this VPS I am using the current configuration which works fine for striaght HTML but will not run the web apps unless I run them on another port (rails s -p3500 etc) as port 80 is already taken up by Apache.
<VirtualHost *:80>
ServerName datumpoint.bizmodev.com
# ServerAlias *.example.com
DocumentRoot /var/www.bizmodev.com
<Directory "/var/www.bizmodev.com">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName homehounduk.co.uk
ServerAlias *.homehounduk.co.uk
DocumentRoot /var/www.homehounduk.co.uk
<Directory "/var/www.homehounduk.co.uk">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Do i need to use passenger or something else to get this working? i have tried changing the virtual hosts to different ports and stuff but just end up getting a 403.
Any help would be appreciated.
this line:
<VirtualHost *:80>
you are telling to your apache that it will listen to anything on port 80
it you change to something like this:
<VirtualHost www.myawesomeurl.com:80>
in this case you are telling apache that everything that comes as a request from this address (www.myawesomeurl.com) on port 80 will use that options.
I think you want something like this:
# Basically your home, like: www.myhome.com
<VirtualHost *:80>
ServerName datumpoint.bizmodev.com
# ServerAlias *.example.com
DocumentRoot /var/www.bizmodev.com
<Directory "/var/www.bizmodev.com">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# Your custom site
<VirtualHost www.something.com:80>
ServerName homehounduk.co.uk
ServerAlias *.homehounduk.co.uk
DocumentRoot /var/www.homehounduk.co.uk
<Directory "/var/www.homehounduk.co.uk">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and dont forget to point the www.something.com to the same ip as the www.myhome.com
Combine this with passenger and you will have one server running many rails apps and many php instances or html pages or anything you want.

Phusion Passenger Rails server - how to access from outside?

I switched from WEBrick to Phussion Passenger following this guide: http://developer.apple.com/library/mac/#featuredarticles/PhusionRails/index.html.
I used PassengerPane to configure it.
Now I can access my app at myapp.local, instead of localhost:3000
However, I don't know how to access it from the outside. It used to be ip:3000
My vhost.conf file looks like this:
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot "/Users/martin/myapp/public"
RackEnv development
<Directory "/Users/martin/myapp/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You need to add ServerAlias YOURIP:
<VirtualHost *:80>
ServerName myapp.local
ServerAlias YOURIP
DocumentRoot "/Users/martin/myapp/public"
RackEnv development
<Directory "/Users/martin/myapp/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can add as many aliases as you want (with real domain names for example).

Resources