Lookaway CMS Services Configuration - Ubuntu 20

Documented by Kyle Bruder on Oct 08, 2020
Last updated on Jun 12, 2021


Ubuntu Server 20 logo

Introduction

Configure the system level services such as Nginx and Gunicorn needed to serve Lookaway CMS. We will need a static directory for Nginx to serve static files, Nginx configuration for your domain, and the System V service file for Gunicorn. Before starting, make sure you are logged in as a user with sudo permissions.


  1. Create the Nginx Static Directory

    Use the following commands to create the Nginx static directory and make the Lookaway service account the owner of the directory.

    Tip: Substitute your user name with "lookaway" if you are not using that user name.

    Caution: You must issue this command from an account that has sudo privileges.

    $ sudo mkdir /var/www/html/static
    $ sudo chown lookaway. /var/www/html/static
    

  2. Gunicorn Start Script and System V File

    Lookaway CMS comes with a shell wrapper with configured specifications for using Gunicorn. The provided System V service file expects the find the Gunicorn start script in "/home/lookaway/gunicorn_start".

    First, copy the start script to your home directory or to any secure directory. Then copy the service file to the System V services directory.

    Next, edit the start script to suit your needs, if desired.

    Then, taking note of the path to which you copied the start script (the copy, not the template from the Lookaway CMS), open the copied service file and ensure the line "ExecStart" are equal to the path of the start script. Also, ensure the "User" and "Group" lines are equal to your Lookaway user.

    Caution: Make sure you are logged in as a user with sudo privileges when using these commands.

    $ sudo cp /home/lookaway/lookaway-env/lookaway/scripts/gunicorn_start /home/lookaway
    $ sudo vi !$ # Edit copied script if desired. Use ':wq' to write and quit
    $ sudo cp /home/lookaway/lookaway-env/lookaway/services/gunicorn.service /etc/systemd/system/lookaway.service
    $ sudo vi !$ # Ensure the User, Group, and ExecStart are correct. Use ':wq' to write and quit
    

    Source: kbruder Tech

  3. Add Lookaway Nginx Configuration to Nginx Sites

    The Lookaway CMS code repository comes with a sample Nginx configuration. This file will need to be modified to meet your needs. At the very least, you will need to add your domain name. For this reason, we need to copy the file then link it so that it does not get overwritten if a new version is pulled.

    Tip: If you are running more than one instance of Lookaway CMS on the same host, you must use a different name for each Nginx ".conf" file.

    Caution: You must issue this command from an account that has sudo privileges.

    $ sudo cp ~lookaway/lookaway-env/lookaway/services/lookaway.conf /etc/nginx/sites-available/lookaway.conf
    $ sudo ln /etc/nginx/sites-available/lookaway.conf /etc/nginx/sites-enabled/lookaway.conf
    

  4. Customize Lookaway Nginx Configuration

    Nginx needs to know what your server is called. This can be a fully qualified domain name for a website or a local IP address for internal use. Server names are defined using the server_name directive and determine which server block is used for a given request. See also “How nginx processes a request”. They may be defined using exact names, wildcard names, or regular expressions. Multiple values can be added separated by whitespace. In this example, the server will process requests sent to anything .example.com and the private IP address 10.0.0.1.

    Nginx also need to know where your "static", "media" and "log" directories and the Gunicorn socket are expected on the filesystem. If you followed our documentation and are using a user named "lookaway", a virtual environment named "lookaway-env", and the path to Lookaway CMS is "/home/lookaway/lookaway-env/lookaway" then the provided template should work as is. If not, you just need to edit the file to suit your needs.

    Tip: Check out the official Nginx documentation for more information.

    Caution: You must edit this file from an account that has sudo privileges.

    /etc/nginx/sites-enabled/lookaway.conf
    upstream app_server {
            server unix:/home/lookaway/lookaway-env/lookaway/gunicorn.sock fail_timeout=0;
    }
    ...
    server {
            server_name 10.0.0.1 www.example.com *.example.com example.com;
            ...
            access_log /home/lookaway/logs/nginx-access.log;
            error_log /home/lookaway/logs/nginx-error.log;
            ...
            location /static/ {
                    alias /var/www/html/static/;
            }
            location /media/ {
                    alias /home/lookaway/lookaway-env/lookaway/media/;
            }
    }
    

    🌐 How nginx processes a request

    🌐 nginx documentation
    Installing nginx Building nginx from Sources Beginner’s Guide Admin’s Guide Controlling nginx Connection processing methods Setting up hashes A debugging log Logging to syslog Configuration file measurement units Command-line par…

Conclusion

The Nginx configuration is in place and customized to your server name and Gunicorn is configured as a service to provide a socket for Nginx to serve Lookaway data. Once your DNS records are configured, the server will be ready to take HTTP and HTTPS requests from web browsers using your domain name.


Referenced by

Lookaway CMS Production Server - Ubuntu 20

Learn how to deploy Lookaway CMS onto a public webserver using Ubuntu 20.04 and PostgreSQL 10.