Apache

Note that this configuration described here will make the server publicly available in the network.

See apache documentation for more details.

Note

For the apache server there is no need for the uWSGI service. Apache has it’s own module mod-wsgi with which the MUSCLE application can be served.

Installation

sudo apt install apache2 libapache2-mod-wsgi-py3
sudo a2enmod rewrite wsgi

Configuration

Configuration for sites have to be placed inside /etc/apache2/sites-available

Serving Backend

Below is a simple working configuration. Note that this is not suited for global use.

Note

This configuration will make the server publicly available in the current network over the IP of the device where it is installed (HTTP only). To make it public it’s recommended to add certificates for HTTPS. However the easiest way to do this is to use Traefik Installation Guide.

This configuration will make the server publicly available with in the current network over the IP of the device where it is installed (HTTP only).

To serve the backend, the module mod-wsgi is used. Read their documentation for more details.

/etc/apache2/sites-available/010-muscle.conf:

<VirtualHost *:80>
    ServerName 0.0.0.0

    Define workdir <PATH_TO_BACKEND>

    WSGIDaemonProcess backend user=<USER> group=www-data threads=5 \
                      python-home=${workdir}/venv python-path=${workdir} home=${workdir}
    # Handle requests for /api only - note to append /api again after the script
    WSGIScriptAlias /api ${workdir}/backend.py/api
    # The object to call is named app in backend.py (mod-wsgi default is application)
    WSGICallableObject app
    # Pass the authorization headers to the app because its validated there and not with apache
    WSGIPassAuthorization On

    <Directory ${workdir}>
        WSGIProcessGroup backend
        WSGIApplicationGroup %{GLOBAL}
        <Files backend.py>
            Order deny,allow
            Allow from all
            Require all granted
        </Files>
    </Directory>

</VirtualHost>

Replace <PATH_TO_BACKEND> with the path to where you have cloned the backend source. Make sure that the virtual environment is setup and working.

Replace <USER> with the owner of the application (linux user).

Serving Frontend

If you want to serve the frontend with the same server as the backend add these lines inside the <VirtualHost *:80> directive of /etc/nginx/sites-available/010-muscle.conf. Otherwise configure a new server as described in the backend section above.

DocumentRoot <PATH_TO_DIST_FOLDER>
DirectoryIndex index.html

<Location />
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_URI} !^/api.*
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
</Location>

Replace <PATH_TO_DIST_FOLDER> with the path to the dist folder of the built frontend preferably /var/www/html/muscle, otherwise its likely you must also configure the permissions.

Activation

To activate the configuration run the following commands:

sudo a2dissite 000-default.conf
sudo a2ensite 010-muscle.conf
sudo service apache2 reload