diff --git a/deployment/ansible/roles/model-my-watershed.app/meta/main.yml b/deployment/ansible/roles/model-my-watershed.app/meta/main.yml index 53b8b58f5..c0fab2048 100644 --- a/deployment/ansible/roles/model-my-watershed.app/meta/main.yml +++ b/deployment/ansible/roles/model-my-watershed.app/meta/main.yml @@ -4,4 +4,4 @@ dependencies: - { role: "azavea.yarn" } - { role: "azavea.nodejs", nodejs_version: "{{ app_nodejs_version }}", nodejs_npm_version: "{{ app_nodejs_npm_version }}" } - { role: "model-my-watershed.celery" } - - { role: "azavea.nginx", nginx_delete_default_site: True } + - { role: "model-my-watershed.nginx", nginx_delete_default_site: True } diff --git a/deployment/ansible/roles/model-my-watershed.geoprocessing/meta/main.yml b/deployment/ansible/roles/model-my-watershed.geoprocessing/meta/main.yml index 60238dcc6..e59960ad7 100644 --- a/deployment/ansible/roles/model-my-watershed.geoprocessing/meta/main.yml +++ b/deployment/ansible/roles/model-my-watershed.geoprocessing/meta/main.yml @@ -2,4 +2,4 @@ dependencies: - { role: "azavea.java" } - { role: "model-my-watershed.base" } - - { role: "azavea.nginx", nginx_delete_default_site: True } + - { role: "model-my-watershed.nginx", nginx_delete_default_site: True } diff --git a/deployment/ansible/roles/model-my-watershed.nginx/defaults/main.yml b/deployment/ansible/roles/model-my-watershed.nginx/defaults/main.yml new file mode 100644 index 000000000..76614cc54 --- /dev/null +++ b/deployment/ansible/roles/model-my-watershed.nginx/defaults/main.yml @@ -0,0 +1,3 @@ +--- +nginx_version: "stable" +nginx_delete_default_site: False diff --git a/deployment/ansible/roles/model-my-watershed.nginx/handlers/main.yml b/deployment/ansible/roles/model-my-watershed.nginx/handlers/main.yml new file mode 100644 index 000000000..159596ed1 --- /dev/null +++ b/deployment/ansible/roles/model-my-watershed.nginx/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Restart Nginx + service: name=nginx state=restarted diff --git a/deployment/ansible/roles/model-my-watershed.nginx/tasks/main.yml b/deployment/ansible/roles/model-my-watershed.nginx/tasks/main.yml new file mode 100644 index 000000000..69d3d636f --- /dev/null +++ b/deployment/ansible/roles/model-my-watershed.nginx/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: Install Nginx + apt: pkg=nginx-full state=present + +- name: Delete default site + file: path=/etc/nginx/sites-enabled/default state=absent + register: delete_default_site + when: nginx_delete_default_site | bool + notify: + - Restart Nginx + +- name: Delete default web root + file: path=/var/www/html state=absent + when: nginx_delete_default_site | bool and delete_default_site is changed + +- name: Check Nginx Upstart service definition exists + stat: path=/etc/init/nginx.conf + register: nginx_upstart + +- name: Configure Nginx log rotation + template: src=logrotate_nginx.j2 dest=/etc/logrotate.d/nginx + when: nginx_upstart.stat.exists + +- name: Configure Nginx + template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf + notify: + - Restart Nginx diff --git a/deployment/ansible/roles/model-my-watershed.nginx/templates/logrotate_nginx.j2 b/deployment/ansible/roles/model-my-watershed.nginx/templates/logrotate_nginx.j2 new file mode 100644 index 000000000..92e628ec3 --- /dev/null +++ b/deployment/ansible/roles/model-my-watershed.nginx/templates/logrotate_nginx.j2 @@ -0,0 +1,18 @@ +/var/log/nginx/*.log { + weekly + missingok + rotate 52 + compress + delaycompress + notifempty + create 0640 www-data adm + sharedscripts + prerotate + if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ + run-parts /etc/logrotate.d/httpd-prerotate; \ + fi \ + endscript + postrotate + service nginx rotate >/dev/null 2>&1 + endscript +} diff --git a/deployment/ansible/roles/model-my-watershed.nginx/templates/nginx.conf.j2 b/deployment/ansible/roles/model-my-watershed.nginx/templates/nginx.conf.j2 new file mode 100644 index 000000000..541317b03 --- /dev/null +++ b/deployment/ansible/roles/model-my-watershed.nginx/templates/nginx.conf.j2 @@ -0,0 +1,34 @@ +user www-data; +worker_processes {{ ansible_processor_count }}; +pid /run/nginx.pid; + +events { + worker_connections 768; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + server_tokens off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} diff --git a/deployment/ansible/roles/model-my-watershed.tiler/meta/main.yml b/deployment/ansible/roles/model-my-watershed.tiler/meta/main.yml index 276dc1fc8..6f1a3e38c 100644 --- a/deployment/ansible/roles/model-my-watershed.tiler/meta/main.yml +++ b/deployment/ansible/roles/model-my-watershed.tiler/meta/main.yml @@ -2,4 +2,4 @@ dependencies: - { role: "model-my-watershed.base" } - { role: "azavea.nodejs", nodejs_version: "{{ tiler_nodejs_version }}", nodejs_npm_version: "{{ tiler_nodejs_npm_version }}" } - - { role: "azavea.nginx", nginx_delete_default_site: True } + - { role: "model-my-watershed.nginx", nginx_delete_default_site: True }