|
| 1 | +# PHP CRUD API Generator - Root Security Configuration |
| 2 | +# Disable directory listing for this project |
| 3 | +Options -Indexes |
| 4 | +# |
| 5 | +# Goal: |
| 6 | +# - Protect sensitive files in the project root (.env, configs, vault, etc.) |
| 7 | +# - Restrict dashboard and health endpoints to trusted IPs only |
| 8 | +# |
| 9 | +# 📖 Full security guide: docs/DASHBOARD_SECURITY.md |
| 10 | + |
| 11 | +# ---------------------------------------------------------------------- |
| 12 | +# 1) Protect .env and other dotfiles in project root |
| 13 | +# ---------------------------------------------------------------------- |
| 14 | + |
| 15 | +<FilesMatch "^\.env"> |
| 16 | + Require all denied |
| 17 | +</FilesMatch> |
| 18 | + |
| 19 | +<FilesMatch "^\.(git|svn|hg|env)"> |
| 20 | + Require all denied |
| 21 | +</FilesMatch> |
| 22 | + |
| 23 | +# ---------------------------------------------------------------------- |
| 24 | +# 2) Protect Admin Dashboard (root/dashboard.html) |
| 25 | +# ---------------------------------------------------------------------- |
| 26 | + |
| 27 | +<Files "dashboard.html"> |
| 28 | + # Apache 2.4+ syntax: only allow localhost by default |
| 29 | + Require ip 127.0.0.1 ::1 |
| 30 | + # To allow additional IPs in production, add lines like: |
| 31 | + # Require ip YOUR.PUBLIC.IP.HERE |
| 32 | +</Files> |
| 33 | + |
| 34 | +# ---------------------------------------------------------------------- |
| 35 | +# 3) Protect Health Endpoint (root/health.php) |
| 36 | +# ---------------------------------------------------------------------- |
| 37 | + |
| 38 | +<Files "health.php"> |
| 39 | + # Apache 2.4+ syntax: only allow localhost by default |
| 40 | + Require ip 127.0.0.1 ::1 |
| 41 | + # To allow monitoring servers in production, add lines like: |
| 42 | + # Require ip 198.51.100.10 |
| 43 | +</Files> |
| 44 | + |
| 45 | +# Optional: Add HTTP Basic Authentication |
| 46 | +# Uncomment and configure if you want password protection |
| 47 | +# |
| 48 | +# <Files "dashboard.html"> |
| 49 | +# AuthType Basic |
| 50 | +# AuthName "Admin Dashboard" |
| 51 | +# AuthUserFile /path/to/.htpasswd |
| 52 | +# Require valid-user |
| 53 | +# </Files> |
| 54 | +# |
| 55 | +# Create password file with: |
| 56 | +# htpasswd -c .htpasswd admin |
| 57 | + |
| 58 | +# Optional: Redirect HTTP to HTTPS (recommended for production) |
| 59 | +# RewriteEngine On |
| 60 | +# RewriteCond %{HTTPS} off |
| 61 | +# RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] |
0 commit comments