Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Security

Put SafeLine WAF in front of a web app on a Linux VPS

Install the SafeLine web application firewall with Docker, lock down its console, move your app behind it, and confirm attacks are blocked before launch.

CloudSat teamNovember 18, 20266 min read
Abstract illustration of a translucent shield-shaped gate standing between streams of incoming light and a small web server
On this pageHow SafeLine sits in the request path

A port firewall lets every request to port 443 through, including the ones carrying SQL injection or a script tag. A web application firewall reads those requests. SafeLine, a GPL-3.0 WAF from Chaitin Tech that you host yourself, sits between visitors and your sites as a reverse proxy and stops malicious HTTP requests before the application sees them. This guide installs it on the same Linux server as the application, closes its admin console to the world, and proves it blocks something before you rely on it.

How SafeLine sits in the request path

Visitors connect to SafeLine on ports 80 and 443. SafeLine terminates TLS, hands each request to its detection engine, and forwards the clean ones to your application, which now listens only on loopback. Under the hood it is a set of Docker containers:

Container Role
safeline-tengine The reverse proxy (an nginx derivative), using the host's network directly
safeline-detector The detection engine that classifies each request
safeline-mgt Web console and API, published on port 9443 by default
safeline-pg PostgreSQL for configuration and logs
Helper containers Supporting services the installer manages for you

Pick an architecture

  • Same server. SafeLine takes ports 80 and 443, the app moves to 127.0.0.1:8080. Cheapest and simplest, and what this guide covers.
  • Dedicated WAF server. SafeLine runs alone and forwards to one or more backend servers, whose firewalls accept web traffic only from the WAF's address. Better isolation, one more server to patch.
  • Behind a CDN. Point the CDN at SafeLine, accept traffic only from the CDN's ranges, and make sure SafeLine reads the visitor address from the header the CDN sets. Otherwise every visitor looks like the CDN, and rate limits punish everyone at once.

Check the requirements

The installer checks for Docker 20 or later with the Compose v2 plugin, at least 1 GB of free memory, 5 GB of free disk, and either an arm64 CPU or an x86_64 CPU with the SSSE3 instruction set, and stops when a check fails. Check before you start:

grep -m1 -o ssse3 /proc/cpuinfo
docker --version && docker compose version
free -h
df -h /

The installer offers to install Docker if it is missing. Remember that the detection engine and its database share memory with your application, so leave headroom beyond the 1 GB minimum.

Install SafeLine

The project documents a one-line installer. Its curl -k flag skips certificate checks, so download the script first, read it, then run it:

curl -fsSL -o safeline-manager.sh https://waf.chaitin.com/release/latest/manager.sh
less safeline-manager.sh
sudo bash safeline-manager.sh --en

--en selects the international edition with an English interface, and --lts picks the long-term support channel instead of the latest release. The script is interactive: choose the install option and accept the default directory, /data/safeline, unless you have a reason to move it. At the end it prints the console address and the admin credentials. Store them in your password manager right away.

Close the console to the world

The console listens on port 9443, and Docker publishes that port with its own packet-filter rules. UFW does not see that traffic, so ufw deny 9443 protects nothing. Filter it outside the server instead.

Option 1: an SSH tunnel. Block 9443 at the provider level entirely and reach the console through SSH:

ssh -L 9443:127.0.0.1:9443 admin@203.0.113.10

Then open https://127.0.0.1:9443 in your browser while the tunnel runs.

Option 2: a source rule. Allow 9443 only from your own fixed address in a firewall outside the server. On CloudSat, a cloud firewall rule with your address as the source does exactly that.

Then sign in, change the password if prompted, and enable the authenticator-app login for the admin account. The console controls what your whole site accepts, so treat it like root.

Move your application behind SafeLine

SafeLine needs ports 80 and 443, so the application has to step back. With nginx, change the server block to listen on loopback only:

server {
    listen 127.0.0.1:8080;
    server_name app.example.com;
    root /var/www/app;
}

Reload nginx and confirm nothing public remains on the web ports:

sudo nginx -t && sudo systemctl reload nginx
sudo ss -ltnp | grep -E ':(80|443|8080)\s'

Your application now sees every request coming from 127.0.0.1. Like most reverse proxies, SafeLine passes the visitor's address in the X-Forwarded-For header. Tell the app or web server to trust that header only from loopback, for example with set_real_ip_from 127.0.0.1; and real_ip_header X-Forwarded-For; in nginx.

Add the site in the console

In the console, add a new application and fill in:

  • the domain, for example app.example.com;
  • the listening ports: 443 with a certificate (upload your own or request one from Let's Encrypt in the console) and 80 if you want plain HTTP handled too;
  • the upstream: http://127.0.0.1:8080.

Point the domain's A and AAAA records at the server if they are not already. Visit the site and check that pages, logins and uploads work exactly as before.

Prove it blocks something

Test against your own site only. First a normal request, then one carrying a harmless script tag in a query string:

curl -sI https://app.example.com/ | head -1
curl -si "https://app.example.com/?q=%3Cscript%3Ealert(1)%3C/script%3E" | head -1

The first should return 200, the second a block status and SafeLine's block page. The attack log in the console lists the request with its detection type. If both succeed, the request is not passing through SafeLine: check DNS and the listening ports.

Tune before you trust it

Watch the attack log daily for the first week. False positives cluster in predictable places: admin panels, rich-text editors, and APIs that legitimately accept HTML or code. Allow those narrowly, by path and parameter, instead of switching protection off for the whole site. The project's own benchmark compares two detection levels, Balance and Strict; start with the balanced level and tighten it once the log is quiet.

Then use the features that fit your traffic: rate limiting on login and password-reset endpoints, the bot challenge for scraping, and the password challenge for staging sites that should never be public. Chaitin also sells a Pro edition with extra features, so check the current edition comparison before you plan around one.

Keep it maintained

Re-run the manager script and choose the upgrade option to move to a new release; your site configuration stays in place. Back up /data/safeline, which holds configuration, certificates and the database. CloudSat also lists SafeLine among its one-click apps if you prefer to start from a prepared server.

FAQ

Does SafeLine replace my firewall?

No. It inspects HTTP and HTTPS only. Keep a cloud or host firewall that admits nothing except the ports you serve, and SSH from your own addresses.

Will a WAF stop every web attack?

No product does. A WAF filters common attack patterns and abusive traffic, which buys time and reduces noise. Patching the application, its plugins and its dependencies still matters more.

Can I run SafeLine with an existing reverse proxy?

Yes, but avoid stacking two proxies on the same ports. Either let SafeLine face the internet and forward to your proxy on a loopback port, or place it behind a CDN. Every extra hop needs the forwarded-address header configured so logs show real visitors.

Where is the source code?

The project lives at github.com/chaitin/SafeLine under the GPL-3.0 license, with releases and an issue tracker.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.