2013-07-29 01:04:02 +02:00
|
|
|
# [Nginx Server Configs](https://github.com/h5bp/server-configs-nginx)
|
|
|
|
|
2019-02-10 22:15:33 +01:00
|
|
|
[![Build Status](https://img.shields.io/travis/h5bp/server-configs-nginx/master.svg)](https://travis-ci.org/h5bp/server-configs-nginx)
|
|
|
|
|
2014-06-22 20:43:43 +02:00
|
|
|
**Nginx Server Configs** is a collection of configuration snippets that can help
|
|
|
|
your server improve the web site's performance and security, while also
|
2013-11-22 11:32:55 +01:00
|
|
|
ensuring that resources are served with the correct content-type and are
|
|
|
|
accessible, if needed, even cross-domain.
|
|
|
|
|
2015-03-25 11:04:11 +01:00
|
|
|
|
2019-02-04 14:09:06 +01:00
|
|
|
## Getting Started
|
2013-11-22 11:32:55 +01:00
|
|
|
|
2019-02-12 12:25:30 +01:00
|
|
|
Using the Nginx server configs repo directly has a few required steps to be able to work.
|
|
|
|
|
2019-02-04 14:09:06 +01:00
|
|
|
* [Nginx Beginners Guide](https://nginx.org/en/docs/beginners_guide.html)
|
|
|
|
* [Nginx Request Processing](https://nginx.org/en/docs/http/request_processing.html)
|
2019-02-12 12:25:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
### Check `nginx.conf` settings
|
|
|
|
|
|
|
|
The first thing to check is that the `nginx.conf` file contains appropriate values for
|
|
|
|
your specific install.
|
|
|
|
|
|
|
|
Most specific variables are:
|
|
|
|
* `user`
|
|
|
|
* `error_log`
|
|
|
|
* `pid`
|
|
|
|
* `access_log`
|
|
|
|
|
|
|
|
### Nginx test and restart
|
|
|
|
|
|
|
|
* To verify Nginx config
|
|
|
|
```shell
|
|
|
|
$ nginx -t
|
|
|
|
```
|
|
|
|
|
|
|
|
* To verify Nginx config with a custom file
|
|
|
|
```shell
|
2019-05-14 16:35:19 +02:00
|
|
|
$ nginx -t -c nginx.conf
|
2019-02-12 12:25:30 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
* To reload Nginx and apply new config
|
|
|
|
```shell
|
2020-04-05 23:12:33 +02:00
|
|
|
$ nginx -s reload
|
2019-02-12 12:25:30 +01:00
|
|
|
```
|
|
|
|
|
2019-02-04 14:09:06 +01:00
|
|
|
|
|
|
|
### Basic structure
|
|
|
|
|
|
|
|
This repository has the following structure:
|
|
|
|
|
|
|
|
```
|
|
|
|
./
|
|
|
|
├── conf.d/
|
|
|
|
│ ├── default.conf
|
|
|
|
│ └── templates/
|
|
|
|
├── h5bp/
|
|
|
|
│ ├── basic.conf
|
|
|
|
│ ├── location/
|
|
|
|
│ └── .../
|
|
|
|
├── mime.types
|
|
|
|
└── nginx.conf
|
|
|
|
```
|
|
|
|
|
|
|
|
* **`conf.d/`**
|
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
This directory should contain all of the `server` definitions.
|
2019-02-04 14:09:06 +01:00
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
Except if they are dot prefixed or non `.conf` extension, all files in this
|
2019-02-04 14:09:06 +01:00
|
|
|
folder **are** loaded automatically.
|
|
|
|
|
|
|
|
* **`templates` folder**
|
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
Files in this folder contain a `server` template for secure and non-secure hosts.
|
2019-02-04 14:09:06 +01:00
|
|
|
They are intended to be copied in the `conf.d` folder with all `example.com`
|
|
|
|
occurrences changed to the target host.
|
|
|
|
|
|
|
|
* **`h5bp/`**
|
|
|
|
|
|
|
|
This directory contains config snippets (mixins) to be included as desired.
|
|
|
|
|
|
|
|
There are two types of config files provided, individual config snippets and
|
|
|
|
combined config files which provide convenient defaults.
|
|
|
|
|
|
|
|
* **`basic.conf`**
|
|
|
|
|
|
|
|
This file loads a small subset of the rules provided by this repository to add
|
|
|
|
expires headers, allow cross domain fonts and protect system files from web
|
|
|
|
access.
|
2019-02-12 12:25:30 +01:00
|
|
|
The `basic.conf` file includes the rules which are recommended to always be
|
|
|
|
defined.
|
2019-02-04 14:09:06 +01:00
|
|
|
|
|
|
|
* **`location/`**
|
|
|
|
|
2019-05-15 18:38:05 +02:00
|
|
|
Files in this folder contain one or more `location` directives. They are intended
|
|
|
|
to be loaded in the `server` context (or, in a nested `location` block).
|
2019-02-04 14:09:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
* **`mime.types`**
|
|
|
|
|
|
|
|
The mime.types file is responsible for mapping file extensions to mime types.
|
|
|
|
|
|
|
|
* **`nginx.conf`**
|
|
|
|
|
2019-05-14 16:35:19 +02:00
|
|
|
The main Nginx config file.
|
2019-02-04 14:09:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
### As a reference
|
|
|
|
|
|
|
|
To use as reference requires no special installation steps, download/checkout the
|
2019-05-14 16:35:19 +02:00
|
|
|
repository to a convenient location and adapt your existing Nginx configuration
|
2019-02-04 14:09:06 +01:00
|
|
|
incorporating the desired functionality from this repository.
|
|
|
|
|
|
|
|
### Directly
|
|
|
|
|
2019-05-14 16:35:19 +02:00
|
|
|
To use directly, replace the Nginx config directory with this repository. for example:
|
2019-02-04 14:09:06 +01:00
|
|
|
|
|
|
|
```shell
|
2020-04-05 23:12:33 +02:00
|
|
|
nginx -s stop
|
2019-02-04 14:09:06 +01:00
|
|
|
cd /etc
|
|
|
|
mv nginx nginx-previous
|
|
|
|
git clone https://github.com/h5bp/server-configs-nginx.git nginx
|
|
|
|
# install-specific edits
|
2020-04-05 23:12:33 +02:00
|
|
|
nginx
|
2019-02-04 14:09:06 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
### Manage sites
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ cd /etc/nginx/conf.d
|
|
|
|
```
|
|
|
|
|
|
|
|
* Creating a new site
|
|
|
|
```bash
|
|
|
|
$ cp templates/example.com.conf .actual-hostname.conf
|
|
|
|
$ sed -i 's/example.com/actual-hostname/g' .actual-hostname.conf
|
|
|
|
```
|
|
|
|
|
|
|
|
* Enabling a site
|
|
|
|
```bash
|
|
|
|
$ mv .actual-hostname.conf actual-hostname.conf
|
|
|
|
```
|
|
|
|
|
|
|
|
* Disabling a site
|
|
|
|
```bash
|
|
|
|
$ mv actual-hostname.conf .actual-hostname.conf
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
2020-04-05 23:12:33 +02:00
|
|
|
$ nginx -s reload
|
2019-02-04 14:09:06 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Support
|
|
|
|
|
2019-02-10 20:33:30 +01:00
|
|
|
* Nginx v**1.8.0**+
|
2013-11-22 11:32:55 +01:00
|
|
|
|
2015-03-25 11:04:11 +01:00
|
|
|
|
2018-11-23 13:28:12 +01:00
|
|
|
## Contributing
|
2013-07-29 01:04:02 +02:00
|
|
|
|
2018-11-23 13:28:12 +01:00
|
|
|
Anyone is welcome to [contribute](.github/CONTRIBUTING.md),
|
|
|
|
however, if you decide to get involved, please take a moment to review
|
|
|
|
the [guidelines](.github/CONTRIBUTING.md):
|
2013-07-29 01:04:02 +02:00
|
|
|
|
2018-11-23 13:28:12 +01:00
|
|
|
* [Bug reports](.github/CONTRIBUTING.md#bugs)
|
|
|
|
* [Feature requests](.github/CONTRIBUTING.md#features)
|
|
|
|
* [Pull requests](.github/CONTRIBUTING.md#pull-requests)
|
2013-07-29 01:04:02 +02:00
|
|
|
|
2015-03-25 11:04:11 +01:00
|
|
|
|
2013-07-29 01:04:02 +02:00
|
|
|
## Acknowledgements
|
|
|
|
|
2018-11-23 13:10:30 +01:00
|
|
|
[Nginx Server Configs](https://github.com/h5bp/server-configs-nginx) is only possible thanks to all the awesome
|
2013-07-29 01:04:02 +02:00
|
|
|
[contributors](https://github.com/h5bp/server-configs-nginx/graphs/contributors)!
|
|
|
|
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
2015-03-25 11:04:11 +01:00
|
|
|
The code is available under the [MIT license](LICENSE.txt).
|