Fixes #11: Add default/simple virtualhost configuration.

pull/15/head 1.2.0
Jeff Geerling 9 years ago
parent 7360d9cb0b
commit 90b6ddd1b3
  1. 4
      README.md
  2. 17
      defaults/main.yml
  3. 4
      tasks/vhosts.yml
  4. 2
      templates/nginx.conf.j2
  5. 25
      templates/vhosts.j2

@ -14,9 +14,9 @@ None.
Available variables are listed below, along with default values (see `defaults/main.yml`):
nginx_vhost_path: /etc/nginx/sites-enabled
nginx_vhosts: []
The path to the vhost configuration folder (where Nginx will look for server configurations).
A list of vhost definitions (server blocks) for Nginx virtual hosts. If left empty, you will need to supply your own virtual host configuration. See the example in `defaults/main.yml` for available server options. If you have a large number of customizations required for your server definition(s), you're likely better off managing the vhost configuration file yourself, leaving this variable set to `[]`.
nginx_remove_default_vhost: false

@ -4,8 +4,19 @@ nginx_worker_connections: "1024"
nginx_client_max_body_size: "64m"
nginx_keepalive_timeout: "65"
nginx_proxy_cache_path: ""
nginx_remove_default_vhost: false
nginx_vhosts: []
# TODO - add example.
nginx_proxy_cache_path: ""
# Example vhost below, showing all available options:
# - {
# listen: "80 default_server", # default: "80 default_server"
# server_name: "example.com", # default: N/A
# root: "/var/www/example.com", # default: N/A
# index: "index.html index.htm", # default: "index.html index.htm"
#
# # Properties that are only added if defined:
# error_page: "",
# access_log: "",
# extra_config: "" # Can be used to add extra config blocks (multiline).
# }

@ -9,14 +9,14 @@
- name: Add managed vhost config file (if any vhosts are configured).
template:
src: vhosts.j2
dest: "{{ nginx_vhost_path }}/vhosts"
dest: "{{ nginx_vhost_path }}/vhosts.conf"
mode: 0644
when: nginx_vhosts
notify: restart nginx
- name: Remove managed vhost config file (if no vhosts are configured).
file:
path: "{{ nginx_vhost_path }}/vhosts"
path: "{{ nginx_vhost_path }}/vhosts.conf"
state: absent
when: not nginx_vhosts
notify: restart nginx

@ -34,5 +34,5 @@ http {
proxy_cache_path {{ nginx_proxy_cache_path }};
{% endif %}
include /etc/nginx/conf.d/*.conf;
include {{ nginx_vhost_path }}/*;
}

@ -1 +1,24 @@
# TODO
{% for vhost in nginx_vhosts %}
server {
listen {{ vhost.listen | default('80 default_server') }};
server_name {{ vhost.server_name }};
root {{ vhost.root }};
index {{ vhost.index | default('index.html index.htm') }};
{% if vhost.error_page is defined %}
error_page {{ vhost.error_page }};
{% endif %}
{% if vhost.access_log is defined %}
access_log {{ vhost.access_log }};
{% endif %}
{% if vhost.return is defined %}
return {{ vhost.return }};
{% endif %}
{% if vhost.extra_parameters is defined %}
{{ vhost.extra_parameters }};
{% endif %}
}
{% endfor %}