Objective
Falcon is Web Framework written in Python.
https://falcon.readthedocs.io/en/stable/index.html
You can run it using wsgi. Openlitespeed supports wsgi and virtualenv. Lets set it up.
Procedure
1. Install lswsgi
lswsgi is wsgi for Openlitespeed.
In below link, complete up to and including “Install WSGI”.
https://openlitespeed.org/kb/python-wsgi-applications/
Make sure to get latest lswsgi bin from here:
https://www.litespeedtech.com/open-source/litespeed-sapi/download
2. Create virtualenv and install falcon
|
|
3. Create sample wsgi.py script
Openlitespeed will by default look for wsgi.py script (you can change this if you want to in Context setting).
Also, it will try invoking application
instance in wsgi.py script. So you must have your wsgi web instance named application
in your python script.
|
|
wsgi.py will have below content:
|
|
4. Setup lswsgi
Access to lsws admin console.
You can use either server configuration or vhost configuration.
I’m going to use vhost with vhost root at /srv/vhadm
and document root at /srv/vhadm/html
.
vhost Basic Tab
Make sure “Enable Scripts/ExtApps” setting is enabled.
vhost General Tab
vhost Context Tab
Open context tab and click on plus button. Select App Server. Next.
Define as below:
URI = /
Location = $DOC_ROOT
Binary Path = <path-to-lswsgi> eg: /usr/local/lsws/fcgi-bin/lswsgi
Application Type = WSGI
Environment = LS_PYTHONBIN=/srv/vhadm/venv/bin/python
Save the changes.
NOTE: the lsws instruction page tells you to also set PYTHONPATH in Environment but this is not required as python searches packages by traversing back from its binary path.
5. Check file permission
In my setup, since External App Set UID Mode
is Not Set in vhost configuration, it will use lsws user to run the script.
Change the file ownership so that lsws user can at least read the wsgi.py file.
In my case, lsws user is www-lsws
.
|
|
6. Configure listener to that vhost and graceful restart the lsws
7. Test if it works correctly
Sample script only accepts endpoint “/things”.
So to test, you will use below url:
http://<your-host>:<your-port>/things
You should receive response with body “Hello World” if successful.