Skip to content
codemicro edited this page Jan 11, 2020 · 4 revisions

Deploying on Apache

Requires Python 3.7 or above

  1. Run sudo apt-get install libapache2-mod-wsgi python-dev

  2. Create a directory in /var/www for the API, and name it something like nexusapi

  3. Put api.py and auth.csv in that folder, and add API keys to that file.

  4. Create a file called api.wsgi and put the following into it

    import sys
    sys.path.insert(0, '/var/www/yourdir')
    
    from api import app as application
  5. Add the following to your Apache config

    WSGIDaemonProcess api user=www-data group=www-data threads=5
    WSGIScriptAlias "/api" "/var/www/yourdir/api.wsgi"
    <Directory /var/www/yourdir>
        WSGIProcessGroup progpilot
        WSGIApplicationGroup %{GLOBAL}
        Require all granted
    </Directory>
    
  6. Restart Apache, and your API should be present at http://www.example.com/api

    1. If you'd like to have the API accessible from another path, change WSGIScriptAlias "/api" to WSGIScriptAlias "/yourpath", meaning you should be able to access the API from http://www.example.com/yourpath

Script rundown

The main API has its own error logging in combination with what Apache will log for you. Any failures or breakages will be logged in a file in the same directory as api.py (herein referred to as the script) called error.log.

There are numerous helper functions in the script with are used in a lot of functions used for requests. Each of these has a fairly self explanatory name, or is fairly explanatory. There are a couple of notable functions:

  • error_frame
    • error_frame will generate JSON for a response based on an error message, a HTTP code and a

Clone this wiki locally