How to Install SWAG on Arch Linux
SWAG (Secure Web Application Gateway) is a Docker-based reverse proxy solution that makes it easier to manage and secure web applications. In this tutorial, we'll cover how to install SWAG on Arch Linux using Docker.
Prerequisites
Before you start, you'll need:
- A Linux distribution with Docker installed (For this tutorial, we're using Arch Linux)
- A domain name
- SSL certificate from a trusted authority or a self-signed certificate
- Your service(s) that you want to proxy
Step 1: Install Docker and Docker-Compose
sudo pacman -S docker docker-compose
sudo systemctl enable docker && sudo systemctl start docker
Verify that Docker and Docker Compose are installed correctly by running the following commands:
docker --version
docker-compose --version
Step 2: Clone SWAG Docker Image
You can clone the SWAG Docker image from the official GitHub repository using the following command:
git clone https://github.com/linuxserver/docker-swag.git
Step 3: Update Environment Variables
Once you've cloned the Docker image, you need to update the .env file located in the root directory with your server configuration settings.
cp docker-compose.example.yml docker-compose.yml
cp env.example .env
nano .env
In the .env file, make the following changes:
URL=<your-domain-name>
SUBDOMAINS=<your-server-subdomain>
TZ=<your-timezone>
Save and close the .env file.
If you don't want to use subdomains, set the SUBDOMAINS variable to *.
Step 4: Add SSL Certificate and Key Pair
Next, add your SSL certificate and key pair for your domain to the swag/config folder.
vim swag/config/nginx/ssl/<your-domain-name>/fullchain.pem
vim swag/config/nginx/ssl/<your-domain-name>/privkey.pem
Step 5: Start Docker Compose
Start the Docker Compose process with the following command:
docker-compose up -d
This will start the SWAG container and configure it with the provided SSL certificate and key. You can check the status of the container with the following command:
docker-compose ps
Step 6: Proxy Your Services
To proxy your services, you can use the default nginx configuration file located in swag/config/nginx/proxy-confs.
cp swag/config/nginx/proxy-confs/default.sample swag/config/nginx/proxy-confs/<your-service-name>.conf
vim swag/config/nginx/proxy-confs/<your-service-name>.conf
In the
server_name <your-service-domain>;
Add the following lines at the end:
location / {
include /config/nginx/proxy.conf;
proxy_pass http://<your-service-ip>:<your-service-port>;
}
Save and close the
Step 7: Restart SWAG
Finally, restart the SWAG container to apply the new configuration changes:
docker-compose restart swag
You're now ready to access your services securely through SWAG, which provides SSL encryption, reverse proxying, and HTTP to HTTPS redirection.
Conclusion
In this tutorial, we've shown you how to install SWAG on Arch Linux using Docker Compose. With this setup, you can securely proxy your services and ensure that your server is protected from outside threats.