2013-11-22 12:20:50 +01:00
|
|
|
[Nginx Server Configs homepage](https://github.com/h5bp/server-configs-nginx)
|
|
|
|
| [Documentation table of contents](TOC.md)
|
|
|
|
|
|
|
|
# Getting started
|
|
|
|
|
2014-01-11 05:21:07 +01:00
|
|
|
Using the Nginx server configs repo directly has a few required steps to be able to work.
|
2013-11-22 12:20:50 +01:00
|
|
|
|
|
|
|
## Check `nginx.conf` settings
|
|
|
|
|
2014-01-11 05:21:07 +01:00
|
|
|
The first thing to check is that the `nginx.conf` file contains appropriate values for
|
2013-11-22 12:20:50 +01:00
|
|
|
your specific install. The web user varies with distribution, in most cases compare to
|
|
|
|
the config file originally present, and use the same user:
|
|
|
|
|
|
|
|
// /etc/nginx-original/nginx.conf
|
|
|
|
user www-data www-data;
|
|
|
|
|
|
|
|
Apply to the runtime config file:
|
|
|
|
|
|
|
|
// /etc/nginx/nginx.conf
|
|
|
|
#user www www;
|
2014-09-30 11:46:34 +02:00
|
|
|
user www-data www-data;
|
2013-11-22 12:20:50 +01:00
|
|
|
|
|
|
|
## Configure logs and pid file
|
|
|
|
|
2014-01-11 05:21:07 +01:00
|
|
|
The location of logs also varies from system to system. To account for this the `nginx.conf`
|
2013-11-22 12:20:50 +01:00
|
|
|
file uses a relative path for logs:
|
|
|
|
|
|
|
|
// /etc/nginx/nginx.conf
|
|
|
|
error_log logs/error.log warn;
|
|
|
|
|
|
|
|
There are two options to configure this appropriately, change the path to point at the folder
|
|
|
|
where logs should be stored:
|
|
|
|
|
|
|
|
// /etc/nginx/nginx.conf
|
|
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
|
|
|
|
Or, setup a symlink to point at the right place:
|
|
|
|
|
|
|
|
cd /etc/nginx
|
|
|
|
ln -s /var/log/nginx logs
|
|
|
|
|
|
|
|
The location of the pid file should also be checked and corrected if necessary.
|
|
|
|
|
|
|
|
## Creating a site definition
|
|
|
|
|
|
|
|
An example server definition is provided in `sites-available/example.com`. Copy the file to
|
|
|
|
`sites-available/yourdomainname.com` and edit appropriately. Verify specifically that
|
|
|
|
the hostname (`example.com`) and the root are specified correctly.
|
|
|
|
|
|
|
|
## Enabling a site
|
|
|
|
|
|
|
|
Activate the new site by linking `yourdomainname.com` into the `sites-enabled` directory:
|
|
|
|
|
|
|
|
cd /etc/nginx/sites-enabled
|
|
|
|
ln -s ../sites-available/yourdomainname.com .
|
|
|
|
|
|
|
|
This will make the server active the next time nginx (re)starts.
|
|
|
|
|
|
|
|
## Verify config and restart nginx
|
2014-06-22 20:43:43 +02:00
|
|
|
Verify the config and restart nginx to apply the changes.
|
|
|
|
|
2014-06-29 13:50:31 +02:00
|
|
|
To verify nginx config (Tests default nginx config file)
|
2014-06-22 20:43:43 +02:00
|
|
|
|
2014-06-29 13:50:31 +02:00
|
|
|
nginx -t
|
|
|
|
|
|
|
|
**OR**
|
|
|
|
|
|
|
|
To verify a particular nginx config file
|
|
|
|
|
|
|
|
nginx -t -c nginx.conf
|
|
|
|
|
|
|
|
This will test the nginx config file and throws error if any. Otherwise test is successful and you can restart nginx.
|
|
|
|
|
2015-02-23 19:18:51 +01:00
|
|
|
Finally reload nginx to apply the changes.
|
2014-06-29 13:50:31 +02:00
|
|
|
|
2015-02-23 10:52:34 +01:00
|
|
|
/etc/init.d/nginx reload
|