From aa6a854bb3900958f87a2cb608e9d5cf9baa901e Mon Sep 17 00:00:00 2001 From: Akos Vandra Date: Mon, 3 Nov 2014 07:26:44 -0800 Subject: [PATCH 1/2] separate logfiles --- defaults/main.yml | 7 +++++-- templates/nginx.conf.j2 | 4 ++++ templates/site.j2 | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 19b00ff..ebdd6c7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,8 +7,11 @@ nginx_http_params: tcp_nopush: "on" tcp_nodelay: "on" keepalive_timeout: "65" - access_log: "/var/log/nginx/access.log" - error_log: "/var/log/nginx/error.log" + +nginx_log_dir: "/var/log/nginx" +nginx_access_log_name: "access.log" +nginx_error_log_name: "error.log" +nginx_separete_logs_per_site: False nginx_sites: - server: diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index e1d3854..5c404b7 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -19,6 +19,10 @@ http { include /etc/nginx/mime.types; default_type application/octet-stream; + + access_log {{ nginx_log_dir}}/{{ nginx_access_log_name}}; + error_log {{ nginx_log_dir}}/{{ nginx_error_log_name}}; + {% for k,v in nginx_http_params.iteritems() %} {{ k }} {{ v }}; {% endfor %} diff --git a/templates/site.j2 b/templates/site.j2 index 60f3bf7..07826a0 100644 --- a/templates/site.j2 +++ b/templates/site.j2 @@ -1,5 +1,10 @@ server { +{% if nginx_separete_logs_per_site == True %} + access_log {{ nginx_log_dir}}/{{ item.server.server_name}}-{{ nginx_access_log_name}}; + error_log {{ nginx_log_dir}}/{{ item.server.server_name}}-{{ nginx_error_log_name}}; +{% endif %} + {% for k,v in item.server.iteritems() %} {% if k.find('location') == -1 and k != 'file_name' %} {{ k }} {{ v }}; From 3a519cf7e5b96db1e8b1be73618a480887f2e00e Mon Sep 17 00:00:00 2001 From: Akos Vandra Date: Mon, 3 Nov 2014 07:48:31 -0800 Subject: [PATCH 2/2] made locations and try_files into arrays --- defaults/main.yml | 26 ++++++++++++++++++++++---- templates/site.j2 | 17 ++++++++++------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index ebdd6c7..9df145d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,12 +19,30 @@ nginx_sites: listen: 8080 server_name: localhost root: "/tmp/site1" - location1: {name: /, try_files: "$uri $uri/ /index.html"} - location2: {name: /images/, try_files: "$uri $uri/ /index.html"} + locations: + - name: / + try_files: + - $uri + - $uri/ + - /index.html + - name: /images/ + try_files: + - $uri + - $uri/ + - /index.html - server: file_name: bar listen: 9090 server_name: ansible root: "/tmp/site2" - location1: {name: /, try_files: "$uri $uri/ /index.html"} - location2: {name: /images/, try_files: "$uri $uri/ /index.html"} + locations: + - name: / + try_files: + - $uri + - $uri/ + - /index.html + - name: /images/ + try_files: + - $uri + - $uri/ + - /index.html diff --git a/templates/site.j2 b/templates/site.j2 index 07826a0..5e7e1e7 100644 --- a/templates/site.j2 +++ b/templates/site.j2 @@ -6,17 +6,20 @@ server { {% endif %} {% for k,v in item.server.iteritems() %} -{% if k.find('location') == -1 and k != 'file_name' %} +{% if k != 'locations' and k != 'file_name' %} {{ k }} {{ v }}; {% endif %} -{% endfor %} +{% endfor %} -{% for k,v in item.server.iteritems() if k.find('location') != -1 %} - location {{ v.name }} { -{% for x,y in v.iteritems() if x != 'name' %} - {{ x }} {{ y }}; +{% for loc in item.server.locations %} + location {{ loc.name }} { +{% for x,y in loc.iteritems() if x != 'name' %} + {% if x == 'try_files' %} + {{ x }} {{ y | join(' ')}}; + {% else %} + {{ x }} {{ y }}; + {% endif %} {% endfor %} } {% endfor %} } -