server-configs-nginx/doc/nginx-conf.md

56 lines
2.3 KiB
Markdown
Raw Normal View History

[Nginx Server Configs homepage](https://github.com/h5bp/server-configs-nginx)
| [Documentation table of contents](TOC.md)
# Nginx.conf
The `nginx.conf` file is the main config file for nginx, which either defines
or includes the whole configuration for the server.
When editing or defining an nginx configuration file - take care to note in
2018-11-23 13:15:44 +01:00
which [context](https://nginx.org/en/docs/beginners_guide.html#conf_structure)
a directive applies.
Below are some notes on a few of the more important/commonly-edited directives.
For detailed information on any particular directive, please see
2018-11-23 13:15:44 +01:00
[the official documentation](https://nginx.org/en/docs/).
## user
2018-11-23 13:15:44 +01:00
The [user directive](https://nginx.org/en/docs/ngx_core_module.html#user)
indicates which user the server will run as. This is typically a user
specifically for web usage such as "www" "www-data".
The webserver user, and file permissions for any application, should be defined/chosen
2018-11-23 13:15:44 +01:00
following [the principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege)
2015-06-04 08:49:42 +02:00
i.e., sufficient privileges to function correctly but no more than that.
## worker_processes
2018-11-23 13:15:44 +01:00
The [worker_processes directive](https://nginx.org/en/docs/ngx_core_module.html#worker_processes)
broadly defines the number of connections nginx can process.
As of version 1.2.5+ and 1.3.8+, nginx supports the value "auto" which will
automatically detect an appropriate value. In earlier versions setting to
the number of CPUs is a good default/starting point.
## error_log
2018-11-23 13:15:44 +01:00
The [error_log directive](https://nginx.org/en/docs/ngx_core_module.html#error_log)
can be defined/overriden in any context. The directive in the main context
defines the log file to use unless otherwise overriden (at http, server or location
level). This must point to a location writable to the webserver user.
The location for log files varies depending on the operating system; one technique
to allow the config files to be ignorant of this is to symlink `/etc/nginx/logs`
to where you would like log files to be located. e.g.:
mkdir /var/log/nginx
cd /etc/nginx
ln -s /var/log/nginx logs
## pid
2018-11-23 13:15:44 +01:00
The [pid directive](https://nginx.org/en/docs/ngx_core_module.html#pid) is used
by nginx to store the process id of the main process. This must point to a writable
location.