Information Systems:InfoNext server - gunicorn
Overview
Gunicorn is the web server (written in Python) that is used to serve Infonext (Django). It runs behind Apache (IBM i HTTP Server), which reverse proxies requests to /inx to gunicorn.
Configuration
Gunicorn (installable with pip e.g Python extensions manager), is installed within the 'inx' virtual environment - the Python environment created for Infonext. It is scheduled to run daily (IBM i Job Scheduler) using the config file located at /inx/inx_gunicorn.py.
Important setup details include the following:
- Runs on the same IP as Infonet (172.30.18.5), but on port 8080.
- Logs to /var/log/inx/access.log and /var/log/inx/error.log. (Recall that Apache instances log to /www/instance_name/logs/.)
- Apache proxies requests to '/inx' to Gunicorn. Gunicorn serves the Django page/app being requested.
- An alias for '/static/' is defined, which maps to '/uwdsrc/inx/static'. Effectively, this means that the Python code within Infonext programs is served by Gunicorn, while the static files for Django (e.g. CSS, image files etc.) will be served like a normal folder by Apache.
Starting and stopping InfoNext
TBA
Background on Apache
Some background on Apache can help clarify the use of (and the need for) gunicorn server.
Apache is the most commonly known web server (maybe nginx too). It is also most commonly regarded as a web server. This is because it is widely used serve static web pages and files (e.g. HTML,CSS etc.). However, Apache is also widely used as an application server and that is how Web Orders and Infonet "programs" are served. Apache is able to serve applications through the use of Apache modules. For WebSmart programs, which are in RPG and use CGI, the Apache module is mod_cgi (or some close variant). For serving Python/Django sites like Infonext, there are several modules available: mod_wsgi (wsgi), mod_fcgi (FastCGI), and mod_python. None are on the supported list of modules for IBM i HTTP Server (the flavor of Apache we use). Moreover, the community seems to recommend using alternative servers for performance reasons.
Besides being a web and application server, Apache can also act as a proxy (and reverse-proxy). That is, it can route certain URL requests to another server. Infonet programs are split into Infonet (WebSmart) and Infonext (Django) pages/apps. Thus, for requests to Infonet (WebSmart) programs, Apache will both route and serve the requests, while for Infonext requests, Apache will merely route them to Gunicorn. (The requests being referred to are URL requests e.g. http://infonet.unipharm.local/some/specific/path/request).
In sum, the key point is that Apache allows for a single point of entry into Infonet, and takes care of (more importantly, hides) the dirty work from having another web server serving some of the site. Fun fact: some sites that serve millions of users use this very mechanism of proxying to distribute requests across a cluster of servers, to achieve load-balancing.