From 6521d90712581cba976a886d2b4bcfed311a0c9b Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 16 Mar 2017 11:37:10 +0100 Subject: [PATCH] library/roles/nginx: Fixes to the generic virtualhost and to the proxy configuration so that all works with nginx installed from the PPA. --- nginx/defaults/main.yml | 4 +++- nginx/templates/nginx-proxy-params.conf.j2 | 4 ++++ nginx/templates/nginx-virthost.j2 | 13 ++++++++++++- nginx/templates/nginx.conf.j2 | 7 ++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nginx/defaults/main.yml b/nginx/defaults/main.yml index 20f867e4..806ff6ee 100644 --- a/nginx/defaults/main.yml +++ b/nginx/defaults/main.yml @@ -45,14 +45,16 @@ nginx_media_cache_expire: 1M nginx_css_js_cache_expire: -1 nginx_reverse_proxy: False +nginx_define_x_real_ip: False nginx_proxy_buffering: "on" nginx_proxy_redirect: "off" nginx_proxy_buffer_size: 128k -nginx_proxy_buffers: 4 256k +nginx_proxy_buffers: '4 {{ nginx_proxy_buffer_size }}' nginx_proxy_busy_buffers_size: 256k nginx_proxy_connect_timeout: 30s nginx_proxy_read_timeout: 480s nginx_proxy_send_timeout: 120s +nginx_proxy_temp_file_write_size: '{{ nginx_proxy_buffer_size }}' nginx_client_max_body_size: 100M nginx_client_body_timeout: 240s diff --git a/nginx/templates/nginx-proxy-params.conf.j2 b/nginx/templates/nginx-proxy-params.conf.j2 index f8cb3b00..572c2530 100644 --- a/nginx/templates/nginx-proxy-params.conf.j2 +++ b/nginx/templates/nginx-proxy-params.conf.j2 @@ -8,6 +8,9 @@ proxy_set_header X-Forwarded-Host $remote_addr; proxy_set_header X-Forwarded-Server $host; {% else %} proxy_set_header Host $host; +{% if nginx_define_x_real_ip %} +proxy_set_header X-Real-IP $remote_addr; +{% endif %} {% endif %} proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; @@ -15,6 +18,7 @@ proxy_buffering {{ nginx_proxy_buffering }}; proxy_buffer_size {{ nginx_proxy_buffer_size }}; proxy_buffers {{ nginx_proxy_buffers }}; proxy_busy_buffers_size {{ nginx_proxy_busy_buffers_size }}; +proxy_temp_file_write_size {{ nginx_proxy_temp_file_write_size }}; proxy_redirect {{ nginx_proxy_redirect }}; proxy_connect_timeout {{ nginx_proxy_connect_timeout }}; proxy_read_timeout {{ nginx_proxy_read_timeout }}; diff --git a/nginx/templates/nginx-virthost.j2 b/nginx/templates/nginx-virthost.j2 index d10134d6..1349db06 100644 --- a/nginx/templates/nginx-virthost.j2 +++ b/nginx/templates/nginx-virthost.j2 @@ -54,6 +54,14 @@ server { client_body_timeout {{ nginx_client_body_timeout }}; {% endif %} + {% if item.additional_options is defined %} + {% for add_opt in item.additional_options %} + + {{ add_opt }}; + + {% endfor %} + {% endif %} + {% if item.websockets is defined and item.websockets %} proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; @@ -63,7 +71,7 @@ server { include /etc/nginx/snippets/nginx-proxy-params.conf; {% if item.proxy_additional_options is defined %} {% for popt in item.proxy_additional_options %} - {{ popt }} + {{ popt }}; {% endfor %} {% endif %} {% if item.locations is defined %} @@ -72,6 +80,9 @@ server { {% if location.target is defined %} proxy_pass {{ location.target }}; {% endif %} + {% if location.extra_conf is defined %} + {{ location.extra_conf }} + {% endif %} {% if location.other_opts is defined %} {% for opt in location.other_opts %} {{ opt }}; diff --git a/nginx/templates/nginx.conf.j2 b/nginx/templates/nginx.conf.j2 index 9dccd9f9..36850fe3 100644 --- a/nginx/templates/nginx.conf.j2 +++ b/nginx/templates/nginx.conf.j2 @@ -1,6 +1,11 @@ user www-data; -worker_processes {{ nginx_workers }}; pid /run/nginx.pid; +{% if nginx_use_ppa %} +worker_processes auto; +include /etc/nginx/modules-enabled/*.conf; +{% else %} +worker_processes {{ nginx_workers }}; +{% endif %} events { worker_connections {{ nginx_worker_connections }};