This project was created to be a "jumping-off point"
to have NGINX
configured as a load-balancer and
reverse-proxy for a number of micro-services under
high load. Don't take my work as gospel, read the
docs and make adjustments based on your needs.
Also, note that you will need to tune your Linux configurations separately. There are several great posts on this topic floating around the internet including this one from the NGINX blog which also covers a lot of the configurations in this repository.
The config files in this project assume that the
default NGINX
file structure is left in-tact and
that this repo is cloned into a sub-directory of the
nginx/conf directory named distributor
. It is also
assumed that your main nginx.conf
is empty except
for an include to the distributor/global.conf
file:
cd /path/to/your/nginx.conf/directory
git clone [email protected]:dgarlitt/nginx-work-distributor.git distributor
mv nginx.conf nginx.conf.original
echo "include distributor/global.conf;" > nginx.conf
In global.conf
the access_log
is turned off,
which disables the writing of access logs for all
routes. Though having the access log disabled
definitely reduces disk I/O, it is likely that you
will want to turn it back on for monitoring. Below
are some of the possible configurations.
Access logs are often an important source of
information and, when enabled, can be tuned
to perform better. Listed below are some additional options for getting better performance from the
access_log
directive.
See the NGINX docs for more info
The access log can be configured to only write when the buffer is full or the flush timeout is reached. By default, NGINX doesn't buffer writes to the access log.
access_log /path/to/log.file buffer=128K flush=30s;
In the above case, the access log will be written to when the 128K buffer fills or when the flush timeout is reached, whichever comes first. In place of buffer
, gzip=[compression-level]
can be specified which will automatically buffer.
Logging could be adjusted to use a condition for more granular control over what is logged by following the the advice of this stackoverflow post.
Alternatively, it could also be changed so that
the access log is enabled by default in the
global.config
:
access_log /some/file/path/to/some.log
and then turned off using access_log off
on a
per-server basis inside of each server
block:
server {
access_log off
more server configs...
}
Note, however, that this would be useless in the
default configuration for this repo, as there is
only one server
block which is located in the
route.config
file.
Additionally, access or error log output can be directed to syslog or a unix-domain socket, see here for more info.
DigitalOcean posted
this great article
with more logging options including how to configure
log-rotation in NGINX
.
Make an effort to tune the keepalive settings to
make sense for your stack. Moreover, optimize the
keepalive
property on a per-upstream basis.
More info from NGINX.
Please be mindful that the files in this repo make
use of some advanced configuration options available
in NGINX
. As such, before using this in your own
projects, it would be wise to go through the files
and make sure you understand each of the settings
and adjust them according to your needs. I cannot
guarantee that these settings will work for
everyone, so use at your own risk. Other than that,
best of luck!
Contributions are always welcome. If you would like to contribute to this project, follow these easy steps:
- Fork this repository
- Create a feature branch for your changes
- If you have a lot of commits, rebase from master and squash your commits to a single commit with a meaningful message
- Make sure that your configurations are passing
sudo nginx -t
- Make sure your commit messages follow this guide
- Open a pull request