Skip to content
gohacks.dev
DevOps

Nginx Config Generator

Generate an Nginx server block for Laravel with PHP-FPM, a Node or Go reverse proxy, a single-page app or a static site, with HTTPS, redirects and gzip.

Free · No sign-up · Your inputs stay in your browser

Input

Generate an Nginx server block

Output

server block

1,845 characters

Uses the http2 on; directive from Nginx 1.25.1; on older versions write listen 443 ssl http2; instead. The Laravel block follows the deployment page of the Laravel docs, including $realpath_root, which keeps symlinked zero-downtime releases from serving the previous release. Test with nginx -t before reloading.

Runs in this browser. Nothing you paste is sent to a server.

The Laravel block

It follows the Nginx configuration in Laravel's deployment docs: the root is public/, every request that is not a file goes to index.php, and only that one PHP file is passed to FastCGI. Using $realpath_root rather than $document_root matters for zero-downtime deploys that switch a current symlink, because it resolves the link and lets PHP's opcache see the new release.

Reverse proxies

An app behind Nginx sees every request coming from 127.0.0.1 unless Nginx passes the client's details in X-Forwarded-For and X-Forwarded-Proto and the app is told to trust them. WebSockets need the Upgrade and Connection headers forwarded, which the map block at the top sets up, as described in Nginx's WebSocket proxying page.

Before reloading

Run sudo nginx -t and only then sudo systemctl reload nginx. A reload with a broken file is refused and the old configuration keeps running; a restart with one takes the site down.

Share

Frequently asked questions

Why do I get 502 Bad Gateway with PHP-FPM?
Nginx cannot reach PHP-FPM: the socket path or port in fastcgi_pass is wrong, PHP-FPM is not running, or the socket's permissions do not let the nginx user connect. The Nginx error log names which.
What does client_max_body_size do?
It caps the request body Nginx accepts, 1 MB by default. Uploads larger than it fail with 413 before PHP sees them; PHP's upload_max_filesize and post_max_size must be raised too.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools