If your access logs are full of requests for /.env, /.git/config or /wp-config.php.bak, automated scanners are looking for secrets your web server might hand out by mistake. Those requests are harmless as long as every one of them gets a 403 or 404. Check your logs for any that got a 200. Deny dotfiles in your web server configuration, and if anything leaked, rotate every secret it contained.
What the scanners are looking for
Bots crawl entire IP ranges and request a fixed list of paths that often hold credentials or source code:
/.env,/.env.production,/.env.local,/api/.env, which hold database passwords, API keys and app secrets (Laravel, Node, Django and many other frameworks use.env)/.git/configand/.git/HEAD. If these answer, the whole repository, including its history, can often be rebuilt/.aws/credentials,/.docker/config.jsonand/.npmrc- backup and dump files:
/backup.sql,/db.sql,/site.zip,config.php.bak,.swpfiles - admin and debug endpoints:
/phpinfo.php,/server-status,/actuator/env
These leaks usually happen because the web root points at the project directory instead of its public/ folder. Another common cause is a deployment that copies the .git folder to the server.
Check your access logs
For nginx with the default combined format, the request path is field 7 and the status is field 9:
# Who asked for dotfiles, and what did they get?
sudo awk '$7 ~ /\/\.(env|git)/ {print $9, $7}' /var/log/nginx/access.log \
| sort | uniq -c | sort -rn | head -20
# The important question: did anything answer 200?
sudo awk '$7 ~ /\/\.(env|git)/ && $9 == 200' /var/log/nginx/access.log
# Include rotated, compressed logs
sudo zgrep -hE '"(GET|HEAD) /[^ ]*\.(env|git)' /var/log/nginx/access.log* \
| awk '$9 == 200'
# Top scanning IPs
sudo awk '$7 ~ /\/\.(env|git)/ {print $1}' /var/log/nginx/access.log \
| sort | uniq -c | sort -rn | head
On Debian and Ubuntu, Apache logs live in /var/log/apache2/access.log. On the RHEL family they are in /var/log/httpd/access_log. The same commands work if you use the combined format.
Then test from outside, the way a bot would:
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/.env
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/.git/config
curl -s https://example.com/.git/HEAD
Anything other than 403 or 404 (or a body like ref: refs/heads/main) means the file is exposed.
Block dotfiles in your web server
The safest fix is to make sure secrets are never inside the web root at all. Point the document root at public/, and deploy build artifacts instead of a git checkout. Add a deny rule anyway, as a second layer. Every rule below still allows /.well-known/, which Let’s Encrypt and other standards need.
nginx
Inside each server block, before other location blocks:
location ~ /\.(?!well-known(?:/|$)) {
return 404;
}
location ~* \.(sql|bak|old|orig|swp|zip|tar\.gz)$ {
return 404;
}
Then run sudo nginx -t && sudo systemctl reload nginx. Returning 404 instead of 403 doesn’t confirm that the file exists. See the nginx location documentation.
Apache 2.4
In the virtual host, or in the main configuration:
RedirectMatch 404 "/\.(?!well-known(/|$))"
RedirectMatch 404 "\.(sql|bak|old|orig|swp)$"
RedirectMatch with a 404 status returns “Not Found” without redirecting. Apply it with sudo apachectl configtest, then reload apache2 (Debian/Ubuntu) or httpd (RHEL family).
Caddy
Caddy’s regular expressions don’t support lookahead, so exclude .well-known with a separate matcher:
example.com {
@hidden {
path_regexp /\.
not path /.well-known/*
}
respond @hidden 404
# ... the rest of your site
}
Reload with sudo systemctl reload caddy. See the Caddy request matchers documentation.
Behind Traefik or Coolify
If the app runs behind a reverse proxy, apply the rule in the app’s own web server. You can also make sure the container image doesn’t contain .env or .git in the first place, with a .dockerignore file.
If something leaked: rotate, don’t just delete
If any .env or .git request returned 200, assume the contents are in someone else’s hands. Deleting the file or adding a deny rule does not undo that.
- Block access now with the rules above, and confirm with
curl. - Find out what was exposed. List every variable in the file. For
.git, assume the whole history is exposed, including secrets that were committed and later removed. - Rotate every secret: database passwords, API keys (payment, email, cloud), the app’s encryption or signing key, OAuth client secrets and SMTP credentials. Revoke the old values; creating new ones is not enough.
- Check for misuse. Look at database logins, cloud provider audit logs and API usage since the first
200in your logs. - Consider your obligations. If personal data may have been accessed, the GDPR requires notifying the supervisory authority within 72 hours of becoming aware of a breach, unless it is unlikely to pose a risk (Article 33).
Block the scanners
Deny rules make the requests fail. Banning the IPs stops the same bot from trying hundreds of other paths. With fail2ban, a small custom filter is enough:
sudo tee /etc/fail2ban/filter.d/nginx-dotfiles.conf >/dev/null <<'EOF'
[Definition]
failregex = ^<HOST> \S+ \S+ \[[^\]]+\] "(?:GET|POST|HEAD) /[^"]*(?:\.env|\.git/|wp-config\.php\.bak)[^"]*" \d{3}
ignoreregex =
EOF
sudo tee /etc/fail2ban/jail.d/nginx-dotfiles.local >/dev/null <<'EOF'
[nginx-dotfiles]
enabled = true
port = http,https
filter = nginx-dotfiles
logpath = /var/log/nginx/access.log
backend = auto
maxretry = 2
findtime = 10m
bantime = 1d
EOF
sudo fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/nginx-dotfiles.conf
sudo systemctl reload fail2ban
sudo fail2ban-client status nginx-dotfiles
Two cautions:
- If your site sits behind a CDN or proxy, the IP at the start of the log line is the proxy’s, so you would ban the proxy. Configure nginx’s
real_ipmodule first so it logs the client address. - If the web server runs in Docker, fail2ban’s default actions work in INPUT, which Docker-published ports skip. Use an action that targets the
DOCKER-USERchain.
How Avanguard helps
- Avanguard reads access logs from nginx, Apache, Traefik, Coolify and Caddy. It raises an alarm when a sensitive file such as
/.envor/.git/configanswers 200, and when someone scans sensitive paths or uses security scanners like sqlmap, nikto or nuclei. - With automatic blocking turned on (opt-in per server), the agent blocks for 24 hours any address that requests at least 3 different sensitive files within 2 minutes, or sends 10 requests with a scanner user agent. Repeat offenders within 7 days are blocked for 7 days.
- Blocks live in the agent’s own
AVANGUARDchain, which is reached from both INPUT andDOCKER-USER, so they also cover containers. Private addresses, your allowlist, Cloudflare networks and known clients from the last 24 hours are never blocked.
See server attack protection for details.
Summary
- Search your access logs for
.envand.gitrequests that returned200 - Test
/.env,/.git/configand/.git/HEADwithcurlfrom outside - Point the web root at
public/and keep.gitand.envout of deployments - Add a dotfile deny rule (nginx, Apache or Caddy) that still allows
/.well-known/ - If anything leaked: rotate and revoke every secret, and check for misuse
- Ban repeat scanners, with the real client IP logged and Docker handled