⚡
usefultools.dev
NGX

Nginx Config Generator – SPA, Reverse Proxy, PHP

NOUVEAU

Nginx config generator for static sites, SPAs, reverse proxies and PHP-FPM, with HTTPS redirect, Let’s Encrypt paths, gzip and security headers. Free.

Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.

Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.

HTTPS
Performance and security
  • info: Using Let's Encrypt paths for example.com. Get the certificate first, e.g. certbot certonly --webroot -w /var/www/certbot -d example.com -d www.example.com.

nginx server blockexample.com.conf

# nginx config for example.com (single-page app) — generated by UsefulTools.dev
# Save as /etc/nginx/conf.d/example.com.conf, then run: nginx -t && systemctl reload nginx

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    # Keep the ACME challenge reachable over HTTP for certificate renewals
    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;  # nginx 1.25.1+; on older versions use "listen 443 ssl http2;"
    server_name example.com www.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers off;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    root /var/www/example.com/dist;
    index index.html;
    client_max_body_size 10M;

    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml application/rss+xml application/manifest+json image/svg+xml;

    # Security headers (a location with its own add_header must repeat them)
    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;

    # Single-page app: unknown paths fall back to index.html for client-side routing
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Never cache the HTML shell so new deploys show up immediately
    location = /index.html {
        add_header Cache-Control "no-cache";
        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;
    }

    # Long cache for fingerprinted static assets
    location ~* \.(?:css|js|mjs|png|jpe?g|gif|webp|avif|svg|ico|woff2?|ttf|eot)$ {
        expires 30d;
        access_log off;
        try_files $uri =404;
    }

    # Block hidden files such as .git and .env
    location ~ /\.(?!well-known) {
        deny all;
    }
}
⚡

Exemples rapides

Des entrées typiques et les résultats produits par cet outil.

SPA
Single-page app
try_files $uri $uri/ /index.html;
Proxy
Reverse proxy + WebSocket
proxy_set_header Upgrade $http_upgrade;
SSL
example.com + HTTPS
/etc/letsencrypt/live/example.com/…
PHP
PHP-FPM
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
📖

Présentation

nginx serves most sites from a server block: listen ports, server names, TLS certificates, a document root or a proxy target, and location rules. This nginx config generator writes that block for four common setups: a static site, a single-page app with an index.html fallback, a reverse proxy to a Node, Python or Go app (with optional WebSocket headers), and PHP through PHP-FPM.

Toggle an HTTP to HTTPS redirect, Let’s Encrypt certificate paths, HTTP/2, gzip, long caching for static assets, security headers, HSTS and an upload size limit. Comments explain the non-obvious lines, such as why the SPA index.html location repeats the security headers. The config is built in your browser.

Pourquoi utiliser cet outil ?

  • Working server block in seconds, not docs tabs
  • Correct WebSocket upgrade map for proxies
  • Avoids the add_header inheritance trap
  • Let’s Encrypt paths filled in from your domain
  • Validation for domains, upstreams and size limits
⭐

Fonctionnalités

🧭

Four site types

Static, SPA, reverse proxy and PHP-FPM templates with the right try_files rules.

🔐

HTTPS ready

Port 80 to 443 redirect, ACME challenge path, TLS 1.2/1.3 and HTTP/2.

⚡

Gzip and caching

Compression for text assets and 30-day expiry for fingerprinted files.

🛡️

Security headers

nosniff, frame options, referrer and permissions policy, optional HSTS.

🔌

WebSocket proxy

Upstream with keepalive plus the $connection_upgrade map.

💾

Named download

Saves as <domain>.conf ready for /etc/nginx/conf.d/.

🛠️

Mode d'emploi

1

Pick the site type

Static site, single-page app, reverse proxy or PHP-FPM.

2

Enter domain and target

Fill in the domains and the document root, upstream or PHP-FPM socket.

3

Choose options

Set HTTPS, certificate paths, gzip, caching, headers and body size.

4

Download and reload

Save the file, run nginx -t and reload nginx.

🤔

Questions fréquentes