server-configs-nginx
Nginx HTTP server boilerplate configs
A collection of ready-to-use Nginx configuration snippets covering security, caching, CORS, and file handling. Use them as a reference or drop them in as a base config for your web server.
This repository is a collection of Nginx configuration files assembled by the HTML5 Boilerplate project. Nginx is a widely used web server, and configuring it well involves a lot of small decisions about performance, security, caching, and file handling. This project packages up those decisions into ready-to-use config snippets so developers do not have to figure them out from scratch.
The configs cover things like setting correct content types for different file formats, adding cache expiry headers, allowing fonts to load across domains, protecting system files from being served publicly, and other settings that improve how a website performs and behaves for visitors.
The repository is organized around a main Nginx config file, a directory of server definitions (one per site), a directory of reusable config snippets, a custom configs directory, and a mime.types file that maps file extensions to their correct content types. The h5bp directory contains the core snippets, including a basic.conf file that loads a recommended minimum set of rules and a location directory with additional per-route directives.
You can use this project in two ways. As a reference, you browse the files and copy the relevant parts into your existing Nginx setup. As a direct replacement, you clone the repository into your server's Nginx config directory and adjust the template files to point at your actual domain names. Site files are enabled or disabled by adding or removing a dot prefix from the filename, which controls whether Nginx loads them automatically.
The project requires Nginx version 1.8.0 or later and is available under the MIT license.
Where it fits
- Copy security and caching headers into an existing Nginx setup without researching each setting from scratch
- Use the repository as a starter config when setting up a new web server for a website or web app
- Enable cross-origin font loading on your Nginx-served site by pulling in the relevant CORS snippet