Blueprints · Laravel & PHP
Beginner
10 min · Nginx
Nginx deny dotfiles
Stages a server snippet that denies requests for dotfiles such as .env and .git.
Baked-in protections
- .env and .git are denied
- The snippet is not loaded into the live vhost
- Nginx is not reloaded
Step 1 · conf
Snippet
/root/portgate-blueprints/deny-dotfiles.conf
Include this inside the server block, then nginx -t and reload.
location ~ /\.(?!well-known) {
deny all;
}
Step 2 · bash
Read-only check
/root/portgate-blueprints/nginx-dot-check.sh
Runs nginx -t when nginx exists. It does not reload.
#!/bin/sh set -eu if command -v nginx >/dev/null 2>&1; then nginx -t || echo "nginx -t failed. The snippet was not loaded." else echo "nginx is not installed." fi