I want to serve multiple different ruby on rails applications using Apache and Passenger via a single domain. The applications all should use the same certificate and I want to deliver the apps using HTTPS as default.
# single domain
domain.example.com
# applications accessible via branches
domain.example.com/app_one
domain.example.com/app_two
I have the following configuration for each of the applications which works fine however only to serve a single application. When I enable multiple of these Apache site configurations then the first application in order of alphabet will answer and the rest does not work.
#app_one.conf
<VirtualHost *:80>
ServerName domain.example.com/app_one
Alias /app_one /var/www/app_one/public
DocumentRoot /var/www/app_one/public
PassengerRuby /usr/local/rvm/gems/ruby-2.3.8/wrappers/ruby
<Directory /var/www/app_one/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.example.com/app_one
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
#app_one-secure.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName domain.example.com/app_one
Alias /app_one /var/www/app_one/public
DocumentRoot /var/www/app_one/public
PassengerRuby /usr/local/rvm/gems/ruby-2.3.8/wrappers/ruby
<Directory /var/www/app_one/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
SSLCertificateFile /etc/encrypt/cert.pem
SSLCertificateKeyFile /etc/encrypt/key.pem
SSLCertificateChainFile /etc/encrypt/keychain.pem
Include /etc/encrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I also made the rails applications respond to the separate sub-branches:
# rails app config.ru
map '/app_one' do
run AppName::Application
end
I guess I have to make the configuration sub-branch depending. However I have no clue on how to do this. I also tried to pack the configuration into a Location
block. However that is restrictive and does not accept all of my configuration. In the end I reverted this again as my configuration was invalid. It would be really nice if somebody you could help me figuring this out.