Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locations should be an array #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,42 @@ 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:
file_name: foo
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
4 changes: 4 additions & 0 deletions templates/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
22 changes: 15 additions & 7 deletions templates/site.j2
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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' %}
{% 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 %}
}