91 lines
3.6 KiB
Plaintext
91 lines
3.6 KiB
Plaintext
## ePortfolio – nginx site config for the linuxserver/nginx container
|
||
## Install: copy to ./Portfolio/config/nginx/site-confs/default.conf
|
||
## then: docker exec nginx_Portfolio nginx -t && docker restart nginx_Portfolio
|
||
## Based on the image's default.conf.sample. Files in site-confs/ are included
|
||
## in the http { } block of /config/nginx/nginx.conf, so map and log_format can live here.
|
||
|
||
# ---------- Access logs with the last part of the IP masked (see legal.html) ----------
|
||
# 203.0.113.42 -> 203.0.113.0 | 2001:db8:abcd:12::1 -> 2001:db8:abcd::
|
||
map $remote_addr $remote_addr_anon {
|
||
~(?P<ip>\d+\.\d+\.\d+)\.\d+$ $ip.0;
|
||
~(?P<ip>[^:]+:[^:]+:[^:]+): $ip::;
|
||
default 0.0.0.0;
|
||
}
|
||
log_format anon '$remote_addr_anon - $remote_user [$time_local] "$request" '
|
||
'$status $body_bytes_sent "$http_referer" "$http_user_agent"';
|
||
|
||
server {
|
||
listen 80 default_server;
|
||
listen [::]:80 default_server;
|
||
listen 443 ssl default_server;
|
||
listen [::]:443 ssl default_server;
|
||
|
||
server_name _;
|
||
include /config/nginx/ssl.conf;
|
||
|
||
# ---------- Real visitor IP behind Nginx Proxy Manager ----------
|
||
# Without this, every visitor has the proxy's IP and the contact form's
|
||
# anti-spam limit (5 messages/hour/IP) would block everyone at once.
|
||
# Tighter: replace the three lines with the Docker network's subnet
|
||
# (docker network inspect proxy-portfolio | grep Subnet).
|
||
set_real_ip_from 172.16.0.0/12;
|
||
set_real_ip_from 10.0.0.0/8;
|
||
set_real_ip_from 192.168.0.0/16;
|
||
real_ip_header X-Forwarded-For;
|
||
real_ip_recursive on;
|
||
|
||
access_log /config/log/nginx/access.log anon;
|
||
|
||
root /config/www;
|
||
index index.html;
|
||
error_page 404 /404.html;
|
||
|
||
# ---------- Security headers ----------
|
||
# Everything (fonts, images, scripts, styles) is served from this domain,
|
||
# and no page uses inline styles or scripts, so the policy can be strict.
|
||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self'; img-src 'self' data:; connect-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'self'; object-src 'none'" always;
|
||
add_header X-Content-Type-Options "nosniff" always;
|
||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
||
add_header X-Frame-Options "DENY" always;
|
||
# HSTS: Nginx Proxy Manager handles HTTPS, enable it there ("HSTS Enabled").
|
||
|
||
# A missing file is a real 404 (never index.html with a 200):
|
||
# otherwise a cache could store a page in place of an image.
|
||
location / {
|
||
try_files $uri $uri/ =404;
|
||
}
|
||
|
||
# ---------- Browser cache ----------
|
||
# "expires" does not cancel the add_header lines above (add_header would).
|
||
# CSS and JS are loaded with ?v=…: bump that number after editing them.
|
||
location ~* \.(?:css|js)$ {
|
||
expires 30d;
|
||
}
|
||
location ~* \.(?:woff2)$ {
|
||
expires 1y;
|
||
}
|
||
location ~* \.(?:png|jpe?g|svg|webp|ico)$ {
|
||
expires 7d;
|
||
}
|
||
location ~* \.(?:html|xml|txt)$ {
|
||
expires -1; # pages, sitemap, robots: always revalidated
|
||
}
|
||
|
||
# ---------- PHP: only contact.php may run ----------
|
||
location = /contact.php {
|
||
fastcgi_pass 127.0.0.1:9000;
|
||
include /etc/nginx/fastcgi_params;
|
||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||
client_max_body_size 32k;
|
||
}
|
||
location ~ \.php$ {
|
||
return 404;
|
||
}
|
||
|
||
# Hidden files (.git, .htaccess, .env…), except Let's Encrypt challenges
|
||
location ~ /\.(?!well-known) {
|
||
return 404;
|
||
}
|
||
}
|