From 07868edf2e6441c20ca8629da1ad8a79f12c3e3f Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Tue, 24 Feb 2015 21:10:22 -0600 Subject: [PATCH] Added extra useful Nginx variables. --- README.md | 20 ++++++++++++++++---- defaults/main.yml | 12 +++++++++++- templates/nginx.conf.j2 | 10 ++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 82fad2d..fd87ae0 100644 --- a/README.md +++ b/README.md @@ -31,17 +31,29 @@ If you are configuring Nginx as a load balancer, you can define one or more upst The user under which Nginx will run. Defaults to `nginx` for RedHat, and `www-data` for Debian. nginx_worker_processes: "1" - nginx_worker_connections: "8192" + nginx_worker_connections: "1024" `nginx_worker_processes` should be set to the number of cores present on your machine. Connections (find this number with `grep processor /proc/cpuinfo | wc -l`). `nginx_worker_connections` is the number of connections per process. Set this higher to handle more simultaneous connections (and remember that a connection will be used for as long as the keepalive timeout duration for every client!). - nginx_client_max_body_size: "64m" + nginx_error_log: "/var/log/nginx/error.log warn" + nginx_access_log: "/var/log/nginx/access.log main buffer=16k" -This value determines the largest file upload possible, as uploads are passed through Nginx before hitting a backend like `php-fpm`. If you get an error like `client intended to send too large body`, it means this value is set too low. +Configuration of the default error and access logs. Set to `off` to disable a log entirely. + + nginx_sendfile: "on" + nginx_tcp_nopush: "on" + nginx_tcp_nodelay: "on" + +TCP connection options. See [this blog post](https://t37.net/nginx-optimization-understanding-sendfile-tcp_nodelay-and-tcp_nopush.html) for more information on these directives. nginx_keepalive_timeout: "65" + nginx_keepalive_requests: "100" -The keepalive timeout. Should be set higher (10s+) if you have more polling-style traffic (AJAX-powered sites especially), or lower (<10s) if you have a site where most users visit a few pages and don't send any further requests. +Nginx keepalive settings. Timeout should be set higher (10s+) if you have more polling-style traffic (AJAX-powered sites especially), or lower (<10s) if you have a site where most users visit a few pages and don't send any further requests. + + nginx_client_max_body_size: "64m" + +This value determines the largest file upload possible, as uploads are passed through Nginx before hitting a backend like `php-fpm`. If you get an error like `client intended to send too large body`, it means this value is set too low. nginx_proxy_cache_path: "" diff --git a/defaults/main.yml b/defaults/main.yml index d80a31a..8f9eb26 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,8 +1,18 @@ --- nginx_worker_processes: "1" nginx_worker_connections: "1024" -nginx_client_max_body_size: "64m" + +nginx_error_log: "/var/log/nginx/error.log warn" +nginx_access_log: "/var/log/nginx/access.log main buffer=16k" + +nginx_sendfile: "on" +nginx_tcp_nopush: "on" +nginx_tcp_nodelay: "on" + nginx_keepalive_timeout: "65" +nginx_keepalive_requests: "100" + +nginx_client_max_body_size: "64m" nginx_proxy_cache_path: "" diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 044cc2d..a43202c 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -1,6 +1,6 @@ user {{ nginx_user }}; -error_log /var/log/nginx/error.log warn; +error_log {{ nginx_error_log }}; pid /var/run/nginx.pid; worker_processes {{ nginx_worker_processes }}; @@ -21,12 +21,14 @@ http { '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main buffer=16k; + access_log {{ nginx_access_log }}; - sendfile on; - #tcp_nopush on; + sendfile {{ nginx_sendfile }}; + tcp_nopush {{ nginx_tcp_nopush }}; + tcp_nodelay {{ nginx_tcp_nodelay }}; keepalive_timeout {{ nginx_keepalive_timeout }}; + keepalive_requests {{ nginx_keepalive_requests }}; #gzip on;