From 05cb864c7c3f1d0c7cdc6995cfd870e67c9a687a Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Wed, 9 Dec 2015 16:46:50 +0100 Subject: [PATCH] Use more vars instead of a bug dirty dict --- README.md | 4 +- defaults/main.yml | 68 ++++++++++++++++--------------- templates/etc/nginx/nginx.conf.j2 | 42 ++++++++++++++----- 3 files changed, 69 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index a03bdaa..46a6904 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,9 @@ Socket: - `nginx_user` - `nginx_worker_processes` - - `nginx_events`: key/value in events block - - `nginx_http`: key/value in http block - `nginx_pid`: daemon pid file + - `nginx_events_*`: all variables in events block + - `nginx_http_*`: all variables in http block ### Vhost management diff --git a/defaults/main.yml b/defaults/main.yml index a6cff9b..64a71c1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -33,43 +33,45 @@ nginx_upstreams: [] nginx_user: 'www-data' nginx_worker_processes: '{{ ansible_processor_vcpus }}' -nginx_events: - worker_connections: '512' - multi_accept: 'on' - use: 'epoll' +# +# Nginx events +# +nginx_events_worker_connections: '512' +nginx_events_multi_accept: 'on' +nginx_events_use: 'epoll' # # Nginx HTTP # -nginx_http: - access_log: 'off' - error_log: 'off' - client_body_buffer_size: '1M' - client_header_buffer_size: '1M' - client_max_body_size: '10M' - large_client_header_buffers: '8 8k' - client_body_timeout: '60' - client_header_timeout: '60' - keepalive_timeout: '30 30' - send_timeout: '120' - ignore_invalid_headers: 'on' - keepalive_requests: '100' - recursive_error_pages: 'on' - sendfile: 'on' - server_name_in_redirect: 'off' - server_tokens: 'off' - tcp_nodelay: 'on' - tcp_nopush: 'on' - reset_timedout_connection: 'on' - gzip: 'on' - gzip_buffers: '16 8k' - gzip_comp_level: '9' - gzip_http_version: '1.0' - gzip_min_length: '0' - gzip_types: 'text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml' - gzip_vary: 'on' - gzip_disable: '"msie6"' -# etag: 'off' +nginx_http_types_hash_max_size: 2048 +nginx_http_default_type: 'application/octet-stream' +nginx_http_access_log: 'off' +nginx_http_error_log: 'off' +nginx_http_client_body_buffer_size: '1M' +nginx_http_client_header_buffer_size: '1M' +nginx_http_client_max_body_size: '10M' +nginx_http_large_client_header_buffers: '8 8k' +nginx_http_client_body_timeout: '60' +nginx_http_client_header_timeout: '60' +nginx_http_keepalive_timeout: '30 30' +nginx_http_send_timeout: '120' +nginx_http_ignore_invalid_headers: 'on' +nginx_http_keepalive_requests: '100' +nginx_http_recursive_error_pages: 'on' +nginx_http_sendfile: 'on' +nginx_http_server_name_in_redirect: 'off' +nginx_http_server_tokens: 'off' +nginx_http_tcp_nodelay: 'on' +nginx_http_tcp_nopush: 'on' +nginx_http_reset_timedout_connection: 'on' +nginx_http_gzip: 'on' +nginx_http_gzip_buffers: '16 8k' +nginx_http_gzip_comp_level: '9' +nginx_http_gzip_http_version: '1.0' +nginx_http_gzip_min_length: '0' +nginx_http_gzip_types: 'text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml' +nginx_http_gzip_vary: 'on' +nginx_http_gzip_disable: '"msie6"' # # Vhosts diff --git a/templates/etc/nginx/nginx.conf.j2 b/templates/etc/nginx/nginx.conf.j2 index 61b5281..06a97a8 100644 --- a/templates/etc/nginx/nginx.conf.j2 +++ b/templates/etc/nginx/nginx.conf.j2 @@ -7,21 +7,43 @@ worker_processes {{ nginx_worker_processes }}; pid {{ nginx_pid }}; events { -{% for key, value in nginx_events.iteritems() %} -{{ "\t%-30s %s" | format(key, value) }}; -{% endfor %} + worker_connections {{ nginx_events_worker_connections }}; + multi_accept {{ nginx_events_multi_accept }}; + use {{ nginx_events_use }}; } http { - types_hash_max_size 2048; + types_hash_max_size {{ nginx_http_types_hash_max_size }}; include /etc/nginx/mime.types; - default_type application/octet-stream; - # From Ansible -{% for key, value in nginx_http.iteritems() %} -{{ "\t%-30s %s" | format(key, value) }}; -{% endfor %} - # /From Ansible + default_type {{ nginx_http_default_type }}; + access_log {{ nginx_http_access_log }}; + error_log {{ nginx_http_error_log }}; + client_body_buffer_size {{ nginx_http_client_body_buffer_size }}; + client_header_buffer_size {{ nginx_http_client_header_buffer_size }}; + client_max_body_size {{ nginx_http_client_max_body_size }}; + large_client_header_buffers {{ nginx_http_large_client_header_buffers }}; + client_body_timeout {{ nginx_http_client_body_timeout }}; + client_header_timeout {{ nginx_http_client_header_timeout }}; + keepalive_timeout {{ nginx_http_keepalive_timeout }}; + send_timeout {{ nginx_http_send_timeout }}; + ignore_invalid_headers {{ nginx_http_ignore_invalid_headers }}; + keepalive_requests {{ nginx_http_keepalive_requests }}; + recursive_error_pages {{ nginx_http_recursive_error_pages }}; + sendfile {{ nginx_http_sendfile }}; + server_name_in_redirect {{ nginx_http_server_name_in_redirect }}; + server_tokens {{ nginx_http_server_tokens }}; + tcp_nodelay {{ nginx_http_tcp_nodelay }}; + tcp_nopush {{ nginx_http_tcp_nopush }}; + reset_timedout_connection {{ nginx_http_reset_timedout_connection }}; + gzip {{ nginx_http_gzip }}; + gzip_buffers {{ nginx_http_gzip_buffers }}; + gzip_comp_level {{ nginx_http_gzip_comp_level }}; + gzip_http_version {{ nginx_http_gzip_http_version }}; + gzip_min_length {{ nginx_http_gzip_min_length }}; + gzip_types {{ nginx_http_gzip_types }}; + gzip_vary {{ nginx_http_gzip_vary }}; + gzip_disable {{ nginx_http_gzip_disable }}; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*;