Guide · Open source
How to use server-configs-nginx: setup, structure and site management
Updated · written with AI from the project's own documentation and checked against our catalogue data
server-configs-nginx is a collection of Nginx configuration files from the H5BP (HTML5 Boilerplate) project. Its goal is to help a site perform better and stay more secure, serve files with correct content types, and allow cross-domain access when you need it. This guide explains how the repository is laid out, how to install it, and how to add and disable sites so you can use it on your own Nginx server.
Quick start
- 1Check the requirements. Confirm you run Nginx v1.8.0 or later and decide whether you want Git for cloning.
- 2Back up your config. Stop Nginx and move your existing config directory aside so you can restore it if needed.
- 3Clone the repository. Clone server-configs-nginx into the nginx directory and make your install-specific edits to nginx.conf.
- 4Test the configuration. Run nginx -t to check the config for errors before applying it.
- 5Add a site. Copy the template in conf.d/templates, rename it to your hostname with a dot prefix, and replace example.com.
- 6Enable the site and reload. Remove the dot prefix to enable the site, then run nginx -s reload.
Check whether this project fits your setup
These files only apply to Nginx servers. They are plain configuration files that you edit by hand, so this is not a point-and-click hosting tool. The project is a good fit if you run your own Nginx server and want sensible defaults, or if you want a reference for well-organized Nginx configs.
- Requires Nginx v1.8.0 or later
- Git is optional, used only to clone the repository
- The README does not explain every individual setting in depth, so review each rule before relying on it
Understand the repository structure
The repository is organized into a few directories and files. Knowing what each one does tells you where to put your own changes.
- conf.d/ holds all the server definitions. Files that are dot-prefixed or do not end in .conf are not loaded automatically. The templates/ folder inside it contains secure and non-secure server templates.
- h5bp/ holds config snippets (mixins) to include where needed. basic.conf adds expires headers, allows cross-domain fonts and protects system files from web access. location/ holds files with location directives meant for the server context or a nested location block.
- custom.d/ holds your custom nginx.conf configuration. Like conf.d/, dot-prefixed files and files without a .conf extension are skipped.
- mime.types maps file extensions to MIME types.
- nginx.conf is the main Nginx config file.
./
├── conf.d/
│ ├── default.conf
│ └── templates/
├── h5bp/
│ ├── basic.conf
│ ├── location/
│ └── .../
├── custom.d/
│ └── .../
├── mime.types
nginx.confInstall by cloning into your Nginx config directory
The README describes a direct install: stop Nginx, move your existing config directory aside as a backup, clone this repository in its place, make your install-specific edits, and start Nginx again. Before you begin, check the values in nginx.conf. The main ones to review are user, error_log, pid and access_log, since they depend on your system.
Keep your existing configuration until the new one is tested. The README's example moves the old directory to nginx-previous.
- Check user, error_log, pid and access_log in nginx.conf
- Keep a backup of your existing config directory
nginx -s stop
cd /etc
mv nginx nginx-previous
git clone https://github.com/h5bp/server-configs-nginx.git nginx
# install-specific edits
nginxTest and reload Nginx safely
Always test the configuration before applying it. nginx -t checks the default config. To test a custom file, pass it with -c. Once the test passes, reload Nginx so the new config takes effect.
nginx -t
nginx -t -c nginx.conf
nginx -s reloadAdd, enable and disable a site
Sites are defined as server blocks in conf.d/. Start from a template, rename it to your hostname, and replace the example.com placeholder. A file in conf.d/ is loaded only if its name does not start with a dot and ends in .conf, so renaming a file with a leading dot is a simple way to disable it. Reload Nginx after each change.
- Creating: copy the template and replace example.com with your host name
- Enabling: remove the leading dot from the file name
- Disabling: add a leading dot to the file name
cd /etc/nginx/conf.d
cp templates/example.com.conf .actual-hostname.conf
sed -i 's/example.com/actual-hostname/g' .actual-hostname.conf
mv .actual-hostname.conf actual-hostname.conf
mv actual-hostname.conf .actual-hostname.conf
nginx -s reloadAdd the shared snippets to your sites
The h5bp/ snippets are meant to be included where you need them, not loaded globally. basic.conf is the file the README describes as covering rules that are recommended to always be defined. Location files are intended for the server context or inside a nested location block. Include only what you need and check each rule against your site.
- basic.conf: expires headers, cross-domain fonts, protection of system files
- location/: files containing location directives for the server context or nested location blocks
What people use it for
- Adding caching headers and protecting system files on a personal Nginx server using basic.conf
- Setting up several sites with a shared, organized layout using conf.d/ and templates
- Using the files as a reference for well-structured Nginx configs when adapting your own setup
- Allowing cross-domain access to fonts for a site that needs it
Frequently asked questions
Do I need to install anything to use server-configs-nginx?
No special installation is required to use it as a reference. You download or clone the repository and adapt your Nginx configuration. To use it directly, you replace your Nginx config directory with the repository and make install-specific edits.
What version of Nginx do I need?
The project lists Nginx v1.8.0 or later as its support requirement. Git is optional and only needed if you want to clone the repository.
Is server-configs-nginx free to use?
The code is available under the MIT license, as stated in the repository's LICENSE.txt.
How do I disable a site without deleting it?
Add a leading dot to its file name in conf.d/, so it no longer ends up loaded automatically, then run nginx -s reload. Remove the dot to enable it again.
Why does my Nginx fail after I added these files?
Start by running nginx -t, which checks the configuration for errors. Also check the user, error_log, pid and access_log values in nginx.conf, since the README names these as the most system-specific settings.
What are alternatives to server-configs-nginx?
Comparable projects include nginx-boilerplate, Mozilla SSL Configuration Generator and Caddy. Caddy is a different web server rather than a set of Nginx files, so it suits users who are not committed to Nginx.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use server-configs-nginx if you run your own Nginx server and want a tested-looking, well-organized starting point with caching, content types and protection of system files. Skip it if you do not run Nginx, want a hosting tool with a graphical interface, or need a config tuned for a specific application, since you will have to read and check each rule yourself.
Install options & downloads