roles/nginx: Use template to configure nginx vhosts

Signed-off-by: Alan Orth <alan.orth@gmail.com>
This commit is contained in:
Alan Orth 2014-08-27 20:03:34 +03:00
parent 75a705ac87
commit 5bbec6716c
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
3 changed files with 14 additions and 20 deletions

View File

@ -23,16 +23,18 @@
file: path=/etc/nginx/conf.d/default.conf state=absent file: path=/etc/nginx/conf.d/default.conf state=absent
tags: nginx 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 - name: Configure nginx vhosts
template: src={{ item }} dest=/etc/nginx/conf.d/{{ inventory_hostname }}.conf mode=0644 owner=root group=root template: src=vhost.conf.j2 dest={{ nginx_confd_path }}/{{ item.nginx_domain_name }}.conf mode=0644 owner=root group=root
with_first_found: with_items: nginx_vhosts
- "../templates/{{ inventory_hostname }}.conf.j2"
- "../templates/default.conf.j2"
notify: notify:
- reload nginx - reload nginx
tags: 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 - name: Configure munin vhost
copy: src=munin.conf dest=/etc/nginx/conf.d/munin.conf mode=0644 owner=root group=root copy: src=munin.conf dest=/etc/nginx/conf.d/munin.conf mode=0644 owner=root group=root
notify: notify:

View File

@ -1,9 +0,0 @@
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}

View File

@ -1,16 +1,17 @@
{% set domain_name = item.nginx_domain_name %}
{% set domain_aliases = item.nginx_domain_aliases | default("") %}
server { server {
listen 80 default_server; listen 80;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html; root {{ nginx_root_prefix }}/{{ domain_name }};
server_name web01.mjanja.co.ke; server_name {{ domain_name }} {{ domain_aliases }};
location / { location / {
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
} }
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html; error_page 500 502 503 504 /50x.html;
location = /50x.html { location = /50x.html {
root /usr/share/nginx/html; root /usr/share/nginx/html;
@ -26,7 +27,7 @@ server {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php5-fpm-sock; fastcgi_pass unix:/var/run/php5-fpm-{{ domain_name }}.sock;
fastcgi_index index.php; fastcgi_index index.php;
# set script path relative to document root in server block # set script path relative to document root in server block
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;