OT: Two or more Rails Apps & Apache

16 views
Skip to first unread message

Ralph Shnelvar

unread,
Jul 7, 2018, 12:09:15 PM7/7/18
to Ruby on Rails: Talk
Hi, this is more than a little off topic but not completely so.

I have a computer dedicated as a Rails server.  I've got everything working for a single rails app.

My environment is:
Ubuntu 16.04
Rails 5.2.0
Ruby 2.3.1p112

Apache
Server version: Apache/2.4.18 (Ubuntu)
Server built:   2018-04-18T14:53:04

Right now I'm clueless how to run two Rails apps in an Apache environment.

A Google search doesn't seem to turn up much that is useful.

Anyone know a good place to find that information or ask the question?

Ralph Shnelvar

Hassan Schroeder

unread,
Jul 7, 2018, 12:23:53 PM7/7/18
to rubyonrails-talk
On Sat, Jul 7, 2018 at 9:08 AM, Ralph Shnelvar <ral...@dos32.com> wrote:

> Right now I'm clueless how to run two Rails apps in an Apache environment.

How are you running the one app via httpd now?

What does running two look like? Different virtual hosts? Same host
name, different URL patterns?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Ralph Shnelvar

unread,
Jul 7, 2018, 1:23:16 PM7/7/18
to rubyonra...@googlegroups.com
Hassan,

How dare you ask such cogent and intelligent questions!  :-)

I'm not sure what "different virtual hosts" means.

What I have are two domains I have purchased.  Call them
www.ThisWorks.com and www.ThisIsNewAndDoesNotWorkYet.com.

Ralph



Saturday, July 7, 2018, 10:23:13 AM, you wrote:


HS> On Sat, Jul 7, 2018 at 9:08 AM, Ralph Shnelvar <


>> Right now I'm clueless how to run two Rails apps in an Apache environment.

HS> How are you running the one app via httpd now?

HS> What does running two look like? Different virtual hosts? Same host
HS> name, different URL patterns?

HS> --
HS> Hassan Schroeder ------------------------
hassan.s...@gmail.com
HS> twitter: @hassan
HS> Consulting Availability : Silicon Valley or remote




Ralph

Hassan Schroeder

unread,
Jul 7, 2018, 1:41:43 PM7/7/18
to rubyonrails-talk
On Sat, Jul 7, 2018 at 10:22 AM, Ralph Shnelvar <ral...@dos32.com> wrote:

> I'm not sure what "different virtual hosts" means.

> What I have are two domains I have purchased. Call them www.ThisWorks.com
> and www.ThisIsNewAndDoesNotWorkYet.com.

A single Apache httpd instance listening on a single IP address can
handle multiple "virtual hosts", e.g. different domains as above.

https://httpd.apache.org/docs/2.4/vhosts/

The question is how are you doing the current single domain? Are
you using mod_proxy to forward to an app running on e.g. Puma,
or are you using Passenger?

If the former, it's easy to have each virtual host have its own proxy
settings defined.

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan

Ralph Shnelvar

unread,
Jul 7, 2018, 3:11:01 PM7/7/18
to Hassan Schroeder
Hassan,

I don't think I am using anything but Apache and Rails.

How can I tell?



One of the things that is confusing me is I have a file
 /etc/apache2/sites-available/ThisWorks.com.conf

How does Apache know which *.conf file to use?

I list my /etc/apache2/sites-available/ThisWorks.com.conf file below.



Thank you for pointing me at the documentation.  I'm going through it now.

Is there a book you can point me at that goes through this stuff in much greater detail?



<VirtualHost ThisWorks.asuscomm.com:80>
       # The ServerName directive sets the request scheme, hostname and port that
       # the server uses to identify itself. This is used when creating
       # redirection URLs. In the context of virtual hosts, the ServerName
       # specifies what hostname must appear in the request's Host: header to
       # match this virtual host. For the default virtual host (this file) this
       # value is not decisive as it is used as a last resort host regardless.
       # However, you must set it for any further virtual host explicitly.
       #ServerName www.example.com

       ServerAdmin ral...@dos32.com
       DocumentRoot /var/www/ThisWorks.com/public_html

       # ServerName /var/www/test.com/public_html
       ServerName ThisWorks.asuscomm.com.com
       ServerAlias www.ThisWorks.asuscomm.com
       ServerAlias www.ThisWorks.com
       
       # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
       # error, crit, alert, emerg.
       # It is also possible to configure the loglevel for particular
       # modules, e.g.
       #LogLevel info ssl:warn

       ErrorLog ${APACHE_LOG_DIR}/error.log
       CustomLog ${APACHE_LOG_DIR}/access.log combined

       # For most configuration files from conf-available/, which are
       # enabled or disabled at a global level, it is possible to
       # include a line for only one particular virtual host. For example the
       # following line enables the CGI configuration for this host only
       # after it has been globally disabled with "a2disconf".
       #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet



Ralph



Saturday, July 7, 2018, 11:41:24 AM, you wrote:


HS> On Sat, Jul 7, 2018 at 10:22 AM, Ralph Shnelvar <


>> I'm not sure what "different virtual hosts" means.

>> What I have are two domains I have purchased.  Call them
www.ThisWorks.com
>> and www.ThisIsNewAndDoesNotWorkYet.com.

HS> A single Apache httpd instance listening on a single IP address can
HS> handle multiple "virtual hosts", e.g. different domains as above.

HS>  
https://httpd.apache.org/docs/2.4/vhosts/

HS> The question is how are you doing the current single domain? Are
HS> you using mod_proxy to forward to an app running on e.g. Puma,
HS> or are you using Passenger?

HS> If the former, it's easy to have each virtual host have its own proxy
HS> settings defined.

HS>  
https://httpd.apache.org/docs/2.4/mod/mod_proxy.html


HS> --
HS> Hassan Schroeder ------------------------
hassan.s...@gmail.com
HS> twitter: @hassan
HS> Consulting Availability : Silicon Valley or remote




Ralph

Hassan Schroeder

unread,
Jul 7, 2018, 4:01:29 PM7/7/18
to rubyonrails-talk
On Sat, Jul 7, 2018 at 12:10 PM, Ralph Shnelvar <ral...@dos32.com> wrote:

> I don't think I am using anything but Apache and Rails.
>
> How can I tell?

How do you start your app on this server? `rails s` or ... ?

> One of the things that is confusing me is I have a file
> /etc/apache2/sites-available/ThisWorks.com.conf
>
> How does Apache know which *.conf file to use?

The VirtualHost/ServerName/ServerAlias directives -- if you tried
to access a different hostname on that same IP address it would
just show the default host (from sites-available).

> Is there a book you can point me at that goes through this stuff in much
> greater detail?

I have no idea about a book; there are probably lots of tutorials out
there. The config files are super well-commented, though, and I'd
just start there, along with the online docs.

Note: the Apache httpd is based on Rob McCool's original NCSA
server circa 1993 so it's pretty "battle-tested" and that includes the
documentation :-)

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan

Ralph Shnelvar

unread,
Jul 7, 2018, 4:13:03 PM7/7/18
to Hassan Schroeder
Hassan,

I start Apache via ...
 sudo apache2ctl start


In terms of sites-available ... where do I find the default host?
I do see something called
 /etc/apache2/sites-available

Does Apache look at all the *.conf files? If not, how does it know which .conf file to look at?

Ralph



Saturday, July 7, 2018, 2:01:08 PM, you wrote:


HS> On Sat, Jul 7, 2018 at 12:10 PM, Ralph Shnelvar <


>> I don't think I am using anything but Apache and Rails.

>> How can I tell?

HS> How do you start your app on this server? `rails s` or ... ?


>> One of the things that is confusing me is I have a file
>>  /etc/apache2/sites-available/ThisWorks.com.conf

>> How does Apache know which *.conf file to use?

HS> The VirtualHost/ServerName/ServerAlias directives -- if you tried
HS> to access a different hostname on that same IP address it would
HS> just show the default host (from sites-available).


>> Is there a book you can point me at that goes through this stuff in much
>> greater detail?

HS> I have no idea about a book; there are probably lots of tutorials out
HS> there. The config files are super well-commented, though, and I'd
HS> just start there, along with the online docs.

HS> Note: the Apache httpd is based on Rob McCool's original NCSA
HS> server circa 1993 so it's pretty "battle-tested" and that includes the
HS> documentation :-)


HS> --
HS> Hassan Schroeder ------------------------
hassan.s...@gmail.com
HS> twitter: @hassan
HS> Consulting Availability : Silicon Valley or remote




Ralph

Hassan Schroeder

unread,
Jul 7, 2018, 5:08:57 PM7/7/18
to rubyonrails-talk
On Sat, Jul 7, 2018 at 1:12 PM, Ralph Shnelvar <ral...@dos32.com> wrote:

> I start Apache via ...
> sudo apache2ctl start

But that's not starting Rails, unless you're running it via CGI
which TBH is something I've never seen. Generally you'd be
using mod_proxy to forward requests to your Rails apps.

> In terms of sites-available ... where do I find the default host?
> I do see something called
> /etc/apache2/sites-available

You probably have a file called ~ '000-default.conf' with the
directive <VirtualHost *:80> -- notice the lack of hostname
and the wildcard * where you'd expect a name.

> Does Apache look at all the *.conf files? If not, how does it know which
> .conf file to look at?

It loads all config at initialization and then matches the http request
Host header to the server name.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan

Ralph Shnelvar

unread,
Jul 7, 2018, 9:14:41 PM7/7/18
to Hassan Schroeder
Hassan,

I am so embarrassed.  I have no idea where in all this code I start Rails.  It just seems to be running when I need it.

You are correct, I do have something called /etc/apache2/sites-available/000-default.conf

You wrote: "It loads all config at initialization"
So, to confirm, it does load all the *.conf files?

Ralph



Saturday, July 7, 2018, 3:08:28 PM, you wrote:


HS> On Sat, Jul 7, 2018 at 1:12 PM, Ralph Shnelvar <


>> I start Apache via ...
>>  sudo apache2ctl start

HS> But that's not starting Rails, unless you're running it via CGI
HS> which TBH is something I've never seen. Generally you'd be
HS> using mod_proxy to forward requests to your Rails apps.


>> In terms of sites-available ... where do I find the default host?
>> I do see something called
>>  /etc/apache2/sites-available

HS> You probably have a file called ~ '000-default.conf' with the
HS> directive <VirtualHost *:80> -- notice the lack of hostname
HS> and the wildcard * where you'd expect a name.


>> Does Apache look at all the *.conf files? If not, how does it know which
>> .conf file to look at?

HS> It loads all config at initialization and then matches the http request
HS> Host header to the server name.


HS> --
HS> Hassan Schroeder ------------------------
hassan.s...@gmail.com
HS> twitter: @hassan
HS> Consulting Availability : Silicon Valley or remote




Ralph

Phil Edelbrock

unread,
Jul 7, 2018, 9:31:33 PM7/7/18
to rubyonra...@googlegroups.com
I use Passenger as the glue between Apache and Rails apps, pretty easy to install and configure.  The free version is often just fine for most.  You can have multiple Rails apps running in different environments (including multiple Ruby installs) if you needed to.  I found it pretty solid.

Info:


Or just 'gem install passenger' for the free version:


Good luck!


Phil




Brandon McClelland

unread,
Jul 9, 2018, 1:33:06 PM7/9/18
to rubyonra...@googlegroups.com
I also use Passenger to manage a Rails app with Apache server. There is a great tutorial put out by Digital Ocean on getting it to  work: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-apache-on-ubuntu-14-04 pay close attention to the section on adding a new .conf file to your site-available folder for Apache.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9090E8AA-35DB-4A57-8370-F2AC4C6184C6%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Brandon McClelland
User Support Technician
Steve Jackson Games
Reply all
Reply to author
Forward
0 new messages