diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml index 28bca7c..59e0df8 100644 --- a/roles/nginx/tasks/main.yml +++ b/roles/nginx/tasks/main.yml @@ -23,16 +23,18 @@ file: path=/etc/nginx/conf.d/default.conf state=absent tags: nginx -# need to modularize so we can have different vhosts in different files (apples.com and bananas.com in separate config files) - name: Configure nginx vhosts - template: src={{ item }} dest=/etc/nginx/conf.d/{{ inventory_hostname }}.conf mode=0644 owner=root group=root - with_first_found: - - "../templates/{{ inventory_hostname }}.conf.j2" - - "../templates/default.conf.j2" + template: src=vhost.conf.j2 dest={{ nginx_confd_path }}/{{ item.nginx_domain_name }}.conf mode=0644 owner=root group=root + with_items: nginx_vhosts notify: - reload nginx tags: nginx +- name: Create vhost document roots + file: path={{ nginx_root_prefix }}/{{ item.nginx_domain_name }} state=directory mode=0755 owner=nginx group=nginx + with_items: nginx_vhosts + tags: nginx + - name: Configure munin vhost copy: src=munin.conf dest=/etc/nginx/conf.d/munin.conf mode=0644 owner=root group=root notify: diff --git a/roles/nginx/templates/default.conf.j2 b/roles/nginx/templates/default.conf.j2 deleted file mode 100644 index 90a47d3..0000000 --- a/roles/nginx/templates/default.conf.j2 +++ /dev/null @@ -1,9 +0,0 @@ -server { - listen 80; - server_name localhost; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } -} diff --git a/roles/nginx/templates/web01.conf.j2 b/roles/nginx/templates/vhost.conf.j2 similarity index 75% rename from roles/nginx/templates/web01.conf.j2 rename to roles/nginx/templates/vhost.conf.j2 index c8d9eb7..ee093a5 100644 --- a/roles/nginx/templates/web01.conf.j2 +++ b/roles/nginx/templates/vhost.conf.j2 @@ -1,16 +1,17 @@ +{% set domain_name = item.nginx_domain_name %} +{% set domain_aliases = item.nginx_domain_aliases | default("") %} + server { - listen 80 default_server; - listen [::]:80 default_server ipv6only=on; + listen 80; - root /usr/share/nginx/html; + root {{ nginx_root_prefix }}/{{ domain_name }}; - server_name web01.mjanja.co.ke; + server_name {{ domain_name }} {{ domain_aliases }}; location / { try_files $uri $uri/ =404; } - error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; @@ -26,7 +27,7 @@ server { #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass php5-fpm-sock; + fastcgi_pass unix:/var/run/php5-fpm-{{ domain_name }}.sock; fastcgi_index index.php; # set script path relative to document root in server block fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;