Nginx

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

See nginx documentation for more details.

Note

This nginx configration works with uWSGI. Make sure that you have the neccessary uWSGI service running for the backend.

Installation

sudo apt install nginx

Configuration

Configuration for sites have to be placed inside /etc/nginx/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.

/etc/nginx/sites-available/muscle_backend:

server {
  listen 80;
  server_name muscle;

  location /api/ {
    include uwsgi_params;
    uwsgi_pass unix:<PATH_TO_SOCKET>;
  }
}

The value of PATH_TO_SOCKET is configured in the backend’s muscle.ini and defaults to /tmp/muscle.sock

Serving Frontend

If you want to serve the webapp with the same server as the backend add these lines inside the server{ } directive of /etc/nginx/sites-available/muscle_backend above location /api/ {...}. Otherwise configure a new server as described in the backend section above.

root <PATH_TO_DIST_FOLDER>;
index index.html index.htm index.nginx-debian.html;

location / {
  # when someone reloads the page we do not want 404 so go to / instead - login again
  try_files $uri $uri/ / =404;
}

Replace <PATH_TO_DIST_FOLDER> with the path to the dist folder of the built frontend.

Activation

To activate the configuration run the following commands:

sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/muscle_backend /etc/nginx/sites-enabled