OT: Two or more Rails Apps & Apache

OT: Two or more Rails Apps & Apache 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

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?

Re: [Rails] OT: Two or more Rails Apps & Apache Hassan, How dare you ask such cogent and intelligent questions! :slight_smile: 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:

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.schroeder@gmail.com **HS> twitter: @hassan

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

  Apache Virtual Host documentation - Apache HTTP Server Version 2.4

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.

  mod_proxy - Apache HTTP Server Version 2.4

Re: [Rails] OT: Two or more Rails Apps & Apache 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? # 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 ralphs@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
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet Ralph Saturday, July 7, 2018, 11:41:24 AM, you wrote: >> I'm not sure what "different virtual hosts" means. >> What I have are two domains I have purchased. Call them** [www.ThisWorks.com](http://www.ThisWorks.com) **>> and** [www.ThisIsNewAndDoesNotWorkYet.com](http://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/](https://httpd.apache.org/docs/2.4/vhosts/) **HS> 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](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html) **HS> -- > Hassan Schroeder ------------------------** hassan.schroeder@gmail.com **HS> twitter: @hassan

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 :slight_smile:

Re: [Rails] OT: Two or more Rails Apps & Apache 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:

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 :slight_smile: – Hassan Schroeder ------------------------__ hassan.schroeder@gmail.com **HS> twitter: @hassan

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.

Re: [Rails] OT: Two or more Rails Apps & Apache 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:

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.schroeder@gmail.com **HS> twitter: @hassan

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:

https://www.phusionpassenger.com/

Or just ‘gem install passenger’ for the free version:

https://www.phusionpassenger.com/library/install/apache/install/oss/rubygems_rvm/

Good luck!

Phil

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.