How to Install SWAG on Debian Latest

In this tutorial, we will guide you through the process of installing SWAG (Secure Web Application Gateway) on Debian Latest. SWAG is a docker container that manages the reverse proxy, SSL, and authentication of all your web applications.

Prerequisites

Before we can install SWAG, we need to ensure that we have the following:

  1. A Debian Latest system.
  2. Docker and Docker Compose installed on the system.
  3. A domain name registered and pointed to your server's IP address.

Step 1: Clone the SWAG Repository

First, we need to clone the SWAG repository to our local system. To do this, run the following command:

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

This will clone the SWAG repository to a directory named docker-swag.

Step 2: Configure SWAG

Next, we need to configure SWAG by editing the .env file located in the docker-swag directory. Open the .env file in your favorite text editor and replace the example values with your own. The following variables need to be updated:

For example, to configure SWAG with the example.com domain, with the www subdomain and the blog subdomain, and your email address, user@example.com, your .env file should look like:

URL=example.com
SUBDOMAINS=www,blog
EMAIL=user@example.com

After updating the values, save and close the file.

Step 3: Start SWAG

Now that we have configured SWAG, we can start the container by running the following command:

docker-compose up -d

This will start the SWAG container in the background. It may take a few minutes to complete if this is the first time running the container.

Step 4: Add Your Web Applications

Once SWAG is up and running, we can add our web applications to it. To do this, we need to create a new configuration file for each web application.

Create a new file in the docker-swag/nginx/proxy-confs directory with the name of your web application, followed by .subdomain.conf. For example, if your web application is named myapp, the filename would be myapp.subdomain.conf.

In this file, we need to define the location of the web application and any additional configurations. Here is an example configuration file for a web application running on port 8000:

# myapp.subdomain.conf

server {
    listen 443 ssl;
    server_name myapp.example.com;

    include /config/nginx/ssl.conf;
    client_max_body_size 0;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Be sure to replace myapp.example.com with your own subdomain and domain name. Save and close the file when finished.

After creating the configuration file, restart the SWAG container by running the following command:

docker-compose restart

Your web application should now be accessible through the subdomain myapp.example.com.

Conclusion

Congratulations! You have successfully installed SWAG on your Debian Latest server and added your first web application to it. You can now add more web applications by creating new configuration files and restarting the SWAG container.

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!