Apache Multiple Instances

Multiple Application Deployments

Jarvis supports running under Apache’s Fast CGI.

Fast CGI allows for caching of scripts, database connections and other components which would otherwise be re-created or recompiled with each inbound request to the Jarvis endpoint. Fast CGI allows for much faster responses and overall reduces the load on the web server serving a Jarvis API.

As a default after installation the configuration installed is setup to utilize a single Fast CGI agent; this works well when a single Jarvis application is deployed; however in situations where multiple Jarvis applications are co-located on a single server it is highly recommended to deploy multiple Fast CGI agents to avoid cross over and conflicts between each deployed application.

Support for multiple Fast CGI agents is handled via the Apache mod_rewrite mechanism and directs inbound requests to dedicated Fast CGI agents for each inbound deployed API endpoint. This differs slightly depending on the deployed operating system with differences primarily being between file paths.

mod_rewrite is chosen as it supports a pass-through mechanism which transfers requests to the target Fast CGI agent without creating a subsequent redirect or additional HTTP request over the wire. mod_proxy can also be used to proxy Fast CGI agent requests however doing so causes an additional HTTP request; which while simpler is less efficient.

The concepts for each operating system deployment while differing aim to achieve the same outcome:

RedHat

Apache on RedHat deploys with mod_rewrite enabled by default. This can be confirmed by checking:

/etc/httpd/conf.modules.d/00-base.conf

Ensuring that the following is uncommented:

LoadModule rewrite_module modules/mod_rewrite.so

Disable the default Jarvis configuration file:

mv /etc/httpd/conf.d/jarvis.conf /etc/httpd/conf.d/jarvis.conf.installed

Create a new Jarvis configuration file which acts as the router to each configuration Jarvis Fast CGI agent:

Note: In our example we use the application n2application however this may be repeated for each deployed application.

nano /etc/httpd/conf.d/jarvis.conf
#
# Rewrite rules to direct differing Jarvis routes to unique FCGI sessions.
#
# In this example we are creating a rule for n2application as the deployed Jarvis configuration.
# Additional RewriteRule's may be added as required.
#

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteRule ^/jarvis-agent/n2application/(.*) /jarvis-n2application/n2application/$1 [PT]

</IfModule>

For each application defined above the following configuration will need to be added to the jarvis.conf file.

The minimum expected configuration for a FCGI script is as follows but may be extended as required:

#
# This file controls the Jarvis Fast CGI agent routing for the n2application deployment.
#

# This is FastCGI.
ScriptAlias /jarvis-n2application "/usr/share/jarvis/cgi-bin/fast-agent-n2application.fcgi"

# Ensure the correct permissions are enabled to activate the fact agent module.
<Directory /usr/share/jarvis/cgi-bin>
        Order deny,allow
        Allow from all
        Require all granted
</Directory>

Finally create a link for the Fast CGI agent script that will be invoked:

ln -s /usr/share/jarvis/cgi-bin/fast-agent.fcgi /usr/share/jarvis/cgi-bin/fast-agent-n2application.fcgi

Apache will need to be restarted for any changes to take hold:

systemctl restart httpd

Ubuntu

Apache on Debian/Ubuntu does not natively deploy with mod_rewrite. This will need to enabled via:

a2enmod rewrite

Disable the default Jarvis configuration file:

mv /etc/apache2/conf-available/jarvis.conf /etc/apache2/conf-available/jarvis.conf.installed

Create a new Jarvis configuration file which acts as the router to each configuration Jarvis Fast CGI agent:

Note: In our example we use the application n2application however this may be repeated for each deployed application.

nano /etc/apache2/conf-available/jarvis.conf
#
# Rewrite rules to direct differing Jarvis routes to unique FCGI sessions.
#
# In this example we are creating a rule for n2application as the deployed Jarvis configuration.
# Additional RewriteRule's may be added as required.
#

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteRule ^/jarvis-agent/n2application/(.*) /jarvis-n2application/n2application/$1 [PT]

</IfModule>

For each application defined above the following configuration will need to be added to the jarvis.conf file.

The minimum expected configuration for a FCGI script is as follows but may be extended as required:

#
# This file controls the Jarvis Fast CGI agent routing for the n2application deployment.
#

# This is FastCGI. Requires "apt-get install libapache2-mod-fcgid" and "a2enmod fcgid".
ScriptAlias /jarvis-n2application "/usr/share/jarvis/cgi-bin/fast-agent-n2application.fcgi"

# Ensure the correct permissions are enabled to activate the fact agent module.
<Directory /usr/share/jarvis/cgi-bin>
        Order deny,allow
        Allow from all
        Require all granted
</Directory>

Finally create a link for the Fast CGI agent script that will be invoked:

ln -s /usr/share/jarvis/cgi-bin/fast-agent.fcgi /usr/share/jarvis/cgi-bin/fast-agent-n2application.fcgi

Enable the configuration files so Apache loads them:

ln -s /etc/apache2/conf-available/jarvis-n2application.conf /etc/apache2/conf-enabled/jarvis-n2application.conf

Apache will need to be restarted for any changes to take hold:

systemctl restart apache2

Server Status

Apache provides a useful utility that may be enabled to visualize where Fast CGI traffic is being routed.

Editing the primary Apache configuration file:

RedHat

nano /etc/httpd/conf/httpd.conf

Ubuntu

nano /etc/apache2/apache2.conf

Add the following to the bottom of the file:

# Enable status page:
<Location "/server-status">
    SetHandler server-status
</Location> 

After restarting Apache a status page will be available under:

http://host-name/server-status