Multi-site nginx bundle: split-file configs for many sites
Fill in several sites (WordPress, Node, static, reverse proxy…) and get shared snippets plus one file per site, packed as tar.gz / zip and extracted into /etc/nginx with one command.
← Single-site generator · First deploy guide
Files (10)
Download .tar.gz Download .zip
/etc/nginx/conf.d/00-nginxcc.conf
# /etc/nginx/conf.d/00-nginxcc.conf — http-level settings shared by all sites (generated by nginx.cc)
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# upstream keepalive needs an empty Connection header
map $http_upgrade $connection_upgrade_keepalive {
default upgrade;
'' '';
}
# gzip on lives in nginx.conf (or each site's general.conf); Debian/Ubuntu's nginx.conf already has gzip on, so repeating it here fails as duplicate
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml application/rss+xml application/atom+xml image/svg+xml;
/etc/nginx/nginxcc/security.conf
add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always; # CSP must be tailored per site; enable it once you are sure it does not block your own scripts: # add_header Content-Security-Policy "default-src 'self'; frame-ancestors 'self'" always;
/etc/nginx/nginxcc/general.conf
# Hidden files (.git, .env, …)
location ~ /\.(?!well-known) {
deny all;
}
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 256;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml application/rss+xml application/atom+xml image/svg+xml;
/etc/nginx/nginxcc/letsencrypt.conf
location ^~ /.well-known/acme-challenge/ {
root /var/www/_letsencrypt;
}
/etc/nginx/nginxcc/ssl.conf
# Mozilla Intermediate (Mozilla Server Side TLS 6.0) ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305; ssl_prefer_server_ciphers off; ssl_session_timeout 1d; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; # No OCSP stapling: Let's Encrypt shut down its OCSP service in 2025.
/etc/nginx/nginxcc/proxy.conf
proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port;
/etc/nginx/nginxcc/php_fastcgi.conf
try_files $fastcgi_script_name =404; # stops /upload/x.jpg/a.php from running as PHP include fastcgi_params; fastcgi_index index.php; fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_hide_header X-Powered-By; fastcgi_read_timeout 120s;
/etc/nginx/conf.d/blog.example.com.conf
# blog.example.com — generated by nginx.cc · WordPress
# Save as /etc/nginx/conf.d/blog.example.com.conf, then nginx -t && systemctl reload nginx
limit_req_zone $binary_remote_addr zone=blog_example_com_login:10m rate=10r/m;
server {
listen 80;
listen [::]:80;
server_name blog.example.com;
# Let's Encrypt validation (renewals use it too)
include nginxcc/letsencrypt.conf;
location / {
return 301 https://blog.example.com$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name blog.example.com;
ssl_certificate /etc/letsencrypt/live/blog.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.example.com/privkey.pem;
include nginxcc/ssl.conf;
server_tokens off;
client_max_body_size 64m;
# Security headers
include nginxcc/security.conf;
add_header Strict-Transport-Security "max-age=63072000" always;
access_log /var/log/nginx/blog.example.com.access.log;
error_log /var/log/nginx/blog.example.com.error.log warn;
include nginxcc/general.conf;
root /var/www/blog.example.com;
index index.php index.html;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$args; # WordPress permalinks
}
# WordPress: no direct access to PHP under wp-includes (TinyMCE excepted)
location = /wp-includes/js/tinymce/wp-tinymce.php {
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
include nginxcc/php_fastcgi.conf;
}
location ~* ^/wp-includes/.*\.php$ {
deny all;
}
# WordPress: no scripts in the uploads directory
location ~* ^/wp-content/uploads/.*\.(?:php|phar|s?html?|swf)$ {
deny all;
}
# WordPress: sensitive files
location ~* ^/(?:xmlrpc\.php|wp-links-opml\.php|wp-config\.php|wp-config-sample\.php|readme\.html|license\.txt)$ {
deny all;
}
# WordPress: login throttling (10 per minute per IP)
location = /wp-login.php {
limit_req zone=blog_example_com_login burst=2 nodelay;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
include nginxcc/php_fastcgi.conf;
}
location ~* \.(?:css(?:\.map)?|js(?:\.map)?|mjs|jpe?g|png|gif|ico|cur|heic|webp|avif|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|svgz?|ttf|ttc|otf|eot|woff2?)$ {
expires 30d;
access_log off;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
include nginxcc/php_fastcgi.conf;
}
}
/etc/nginx/conf.d/app.example.com.conf
# app.example.com — generated by nginx.cc · Node.js
# Save as /etc/nginx/conf.d/app.example.com.conf, then nginx -t && systemctl reload nginx
server {
listen 80;
listen [::]:80;
server_name app.example.com;
# Let's Encrypt validation (renewals use it too)
include nginxcc/letsencrypt.conf;
location / {
return 301 https://app.example.com$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name app.example.com;
ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;
include nginxcc/ssl.conf;
server_tokens off;
client_max_body_size 64m;
# Security headers
include nginxcc/security.conf;
add_header Strict-Transport-Security "max-age=63072000" always;
access_log /var/log/nginx/app.example.com.access.log;
error_log /var/log/nginx/app.example.com.error.log warn;
include nginxcc/general.conf;
# Next.js hashed assets can be cached long-term (drop this block for other frameworks)
location /_next/static/ {
proxy_pass http://127.0.0.1:3000;
include nginxcc/proxy.conf;
expires 1y;
access_log off;
}
location / {
proxy_pass http://127.0.0.1:3000;
include nginxcc/proxy.conf;
}
}
/etc/nginx/conf.d/www.example.org.conf
# www.example.org — generated by nginx.cc · Static site
# Save as /etc/nginx/conf.d/www.example.org.conf, then nginx -t && systemctl reload nginx
server {
listen 80;
listen [::]:80;
server_name www.example.org;
# Let's Encrypt validation (renewals use it too)
include nginxcc/letsencrypt.conf;
location / {
return 301 https://www.example.org$request_uri;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
server_name www.example.org;
ssl_certificate /etc/letsencrypt/live/www.example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.org/privkey.pem;
include nginxcc/ssl.conf;
server_tokens off;
client_max_body_size 64m;
# Security headers
include nginxcc/security.conf;
add_header Strict-Transport-Security "max-age=63072000" always;
access_log /var/log/nginx/www.example.org.access.log;
error_log /var/log/nginx/www.example.org.error.log warn;
include nginxcc/general.conf;
root /var/www/www.example.org;
index index.html;
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
location / {
try_files $uri $uri/ =404;
}
location ~* \.(?:css(?:\.map)?|js(?:\.map)?|mjs|jpe?g|png|gif|ico|cur|heic|webp|avif|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|svgz?|ttf|ttc|otf|eot|woff2?)$ {
expires 30d;
access_log off;
}
}
Install
- No certificates yet? Install the HTTP-only bundle first (stage 1)
sudo mkdir -p /var/www/_letsencrypt curl -fsSL 'https://nginx.cc/api/gen/bundle.tar.gz?site=s%3Dwordpress%26domain%3Dblog.example.com%26https%3D0%26www%3Dnone&site=s%3Dnode%26domain%3Dapp.example.com%26https%3D0%26www%3Dnone%26upstream%3D127.0.0.1%253A3000&site=s%3Dstatic%26domain%3Dwww.example.org%26https%3D0%26www%3Dnone&lang=en' | sudo tar -xzf - -C /etc/nginx sudo nginx -t && sudo systemctl reload nginx
- Issue certificates
sudo certbot certonly --webroot -w /var/www/_letsencrypt -d blog.example.com --cert-name blog.example.com --deploy-hook "systemctl reload nginx" sudo certbot certonly --webroot -w /var/www/_letsencrypt -d app.example.com --cert-name app.example.com --deploy-hook "systemctl reload nginx" sudo certbot certonly --webroot -w /var/www/_letsencrypt -d www.example.org --cert-name www.example.org --deploy-hook "systemctl reload nginx"
- Back up, extract, test, reload
sudo cp -a /etc/nginx /etc/nginx.bak.$(date +%Y%m%d-%H%M%S) curl -fsSL 'https://nginx.cc/api/gen/bundle.tar.gz?site=s%3Dwordpress%26domain%3Dblog.example.com%26https%3D1%26www%3Dnone&site=s%3Dnode%26domain%3Dapp.example.com%26https%3D1%26www%3Dnone%26upstream%3D127.0.0.1%253A3000&site=s%3Dstatic%26domain%3Dwww.example.org%26https%3D1%26www%3Dnone&lang=en' | sudo tar -xzf - -C /etc/nginx sudo nginx -t && sudo systemctl reload nginx
If nginx -t fails, restore: sudo rm -rf /etc/nginx && sudo mv /etc/nginx.bak./etc/nginx
Archive paths are relative to /etc/nginx; nginxcc/README.txt repeats these commands. Shared snippets go to /etc/nginx/nginxcc/ and never overwrite distro files (except nginx.conf when you include it).