-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx-security.conf
More file actions
58 lines (52 loc) · 2.33 KB
/
Copy pathnginx-security.conf
File metadata and controls
58 lines (52 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# ── DMARC Viewer — Recommended Nginx Security Configuration ──
# Add this inside your server {} block in nginx.conf or site config.
# Provides security headers that complement the application-level headers.
# ── Security headers ──
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
# ── Content Security Policy ──
# Allows scripts only from self and cdnjs.cloudflare.com (where our CDN libs are served).
# If you move to self-hosted JS, remove the cdnjs entry and add 'nonce-{random}' instead.
add_header Content-Security-Policy "
default-src 'self';
script-src 'self' https://cdnjs.cloudflare.com;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com;
font-src https://fonts.gstatic.com;
connect-src 'self' https://ipwho.is https://ipapi.co;
img-src 'self' data:;
frame-src 'none';
frame-ancestors 'none';
base-uri 'self';
form-action 'self';
" always;
# ── PHP file access restriction ──
# Only allow the three specific PHP endpoints, block all others.
location ~ \.php$ {
# Whitelist only the specific files needed
if ($uri !~ "^/(iplookup|spf-lookup|dkim-lookup)\.php$") {
return 403;
}
# Standard PHP-FPM pass (adjust to your setup)
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# ── Block access to hidden files and sensitive paths ──
location ~ /\. {
deny all;
return 404;
}
# ── Rate limiting ──
# Define rate limit zones (place in http {} block, above server {})
# limit_req_zone $binary_remote_addr zone=dmarc_api:10m rate=30r/m;
# Then inside location blocks for PHP:
# limit_req zone=dmarc_api burst=10 nodelay;
# ── Cache static files ──
location ~* \.(html|css|js|woff2?)$ {
expires 1h;
add_header Cache-Control "public, must-revalidate";
}