How to Install SWAG on macOS

SWAG (Secure Web Application Gateway) is a popular solution for providing SSL/TLS encryption and reverse proxying for web applications. In this tutorial, we will guide you through the process of installing SWAG on macOS using Docker.

Prerequisites

Before starting the installation, make sure that you have the following prerequisites:

Step 1: Clone the SWAG Repository

The first step is to clone the SWAG repository from GitHub. Open Terminal on your Mac and run the following command to clone the repository:

git clone https://github.com/linuxserver/docker-swag.git

This will create a new directory called docker-swag in your current directory, which contains the necessary files for running SWAG with Docker.

Step 2: Configure Environment Variables

Next, you need to set up the environment variables for SWAG. Open Terminal and navigate to the docker-swag directory using the cd command:

cd docker-swag

Inside the directory, you will find a file called .env.example. Make a copy of this file and name it .env:

cp .env.example .env

Open the .env file using a text editor and set the following environment variables:

Save the file and close the text editor.

Step 3: Generate SSL Certificates

Before starting the SWAG container, you need to generate SSL certificates for your domain. SWAG uses the Let's Encrypt certificate authority to issue free SSL certificates that are valid for 90 days.

To generate the certificates, run the following command in Terminal:

docker-compose run --rm --entrypoint "/usr/bin/openssl" swag req -newkey rsa:2048 -nodes -keyout "/config/keys/letsencrypt.key" -out "/config/keys/letsencrypt.csr" -subj "/C=US/ST=State/L=City/O=Organization/OU=Department/CN=yourdomain.com"

Replace yourdomain.com with your actual domain name.

Next, run the following command to obtain an SSL certificate from Let's Encrypt:

docker-compose run --rm swag

This will start the SWAG container and obtain an SSL certificate for your domain. You should see a message that says "Obtaining a new certificate" followed by "Certificate renewal process completed".

Step 4: Start SWAG

After generating the SSL certificates, you can start the SWAG container using Docker Compose. Run the following command in Terminal:

docker-compose up -d

This will start the SWAG container in the background, and you can use it to proxy traffic to your web applications.

Step 5: Test SWAG and Your Web Applications

To test SWAG, open a web browser and access your domain using HTTPS (for example, https://yourdomain.com). You should see a "Secure Connection" message in your browser, indicating that your connection is encrypted with SSL/TLS.

You can also use SWAG to proxy traffic to your web applications. To do this, you need to configure the reverse proxy settings for each application in the docker-compose.yml file. For more information on how to do this, refer to the SWAG documentation.

Congratulations! You have successfully installed SWAG on macOS using Docker. Enjoy the benefits of secure web application gateway!

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!