How to Install SWAG on Ubuntu Server Latest
SWAG (Secure Web Application Gateway) is a docker container from Linuxserver that acts as a reverse proxy and provides easy SSL encryption for your web applications. In this tutorial, we will walk you through the steps to install SWAG on Ubuntu Server Latest.
Prerequisites
To follow this tutorial, you should have:
- An Ubuntu server with Docker and Docker Compose installed
- A fully qualified domain name (FQDN) pointing to the IP address of your server
- Basic knowledge of Linux terminal commands
Step 1: Create a directory for the SWAG configuration
We will create a directory to store the SWAG configuration files. In the terminal, run:
sudo mkdir -p /mnt/docker/swag
Step 2: Download the SWAG configuration files
We will download the SWAG configuration files from the Linuxserver repository on GitHub. In the terminal, run:
sudo curl https://raw.githubusercontent.com/linuxserver/docker-swag/master/config/nginx/site-confs/default > /mnt/docker/swag/nginx/site-confs/default
sudo curl https://raw.githubusercontent.com/linuxserver/docker-swag/master/config/nginx/site-confs/subdomain.template > /mnt/docker/swag/nginx/site-confs/subdomain.template
sudo curl https://raw.githubusercontent.com/linuxserver/docker-swag/master/config/nginx/keys/dhparams.pem > /mnt/docker/swag/nginx/keys/dhparams.pem
Step 3: Create the SWAG docker-compose.yml file
We will create the SWAG docker-compose.yml file and configure it to use the SWAG configuration files. In the terminal, run:
sudo vi /mnt/docker/swag/docker-compose.yml
Copy and paste the following code into the file:
version: "2.1"
services:
swag:
image: linuxserver/swag
container_name: swag
restart: unless-stopped
ports:
- 80:80
- 443:443
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London #change this to your timezone
- URL=your-domain.com #change this to your domain name
- SUBDOMAINS=wildcard
- VALIDATION=http
volumes:
- /mnt/docker/swag/nginx:/config
Save the file and exit the editor.
In the environment section, replace PUID and PGID with your user ID and group ID. You can find them by running the id command in the terminal. Replace TZ with your timezone.
In the URL field, replace your-domain.com with your own domain name. In the SUBDOMAINS field, set it to wildcard if you want to create subdomains automatically. Set it to www,subdomain,your-domain if you want to create subdomains manually.
Step 4: Start the SWAG container
We will start the SWAG container using the docker-compose.yml file we created. In the terminal, run:
cd /mnt/docker/swag
sudo docker-compose up -d
This command will start the SWAG container in detached mode, meaning it will run in the background.
Step 5: Verify the SWAG installation
To verify that SWAG is installed and running properly, open a web browser and go to https://your-domain.com. You should see the default NGINX welcome page with a padlock icon in the address bar, indicating that the connection is secure.
If you want to add a web application to SWAG, follow these steps:
- Create a directory for the application configuration files in
/mnt/docker/swag/nginx/site-confs/ - Copy the
subdomain.templatefile to the new directory and rename it toappName.conf - Edit the
appName.conffile to point to the correct IP address and port of your application - Restart the SWAG container by running
sudo docker-compose restart
Congratulations, you have successfully installed SWAG on Ubuntu Server Latest and added a web application to it.