diff --git a/tasks/vhosts.yml b/tasks/vhosts.yml index 05af037..ca37e02 100644 --- a/tasks/vhosts.yml +++ b/tasks/vhosts.yml @@ -32,6 +32,23 @@ with_items: "{{ nginx_vhosts }}" notify: reload nginx +- name: Enable managed vhost config files. + file: + src: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}" + dest: "{{ nginx_vhost_symlink_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}" + state: link + when: nginx_vhost_symlink_path is defined and item.enabled|default(true) != false + with_items: "{{ nginx_vhosts }}" + notify: reload nginx + +- name: Disable managed vhost config files. + file: + path: "{{ nginx_vhost_symlink_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}" + state: absent + when: nginx_vhost_symlink_path is defined and item.enabled|default(true) == false + with_items: "{{ nginx_vhosts }}" + notify: reload nginx + - name: Remove legacy vhosts.conf file. file: path: "{{ nginx_vhost_path }}/vhosts.conf" diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 7cdec60..76f0b8d 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -72,7 +72,9 @@ http { {% block http_includes %} include {{ nginx_conf_path }}/*.conf; -{% if nginx_conf_path != nginx_vhost_path %} +{% if nginx_vhost_symlink_path is defined %} + include {{ nginx_vhost_symlink_path }}/*; +{% elif nginx_conf_path != nginx_vhost_path %} include {{ nginx_vhost_path }}/*; {% endif %} {% endblock %} diff --git a/vars/Debian.yml b/vars/Debian.yml index cb12770..d6c2012 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -4,6 +4,7 @@ nginx_conf_path: /etc/nginx/conf.d nginx_conf_file_path: /etc/nginx/nginx.conf nginx_mime_file_path: /etc/nginx/mime.types nginx_pidfile: /run/nginx.pid -nginx_vhost_path: /etc/nginx/sites-enabled +nginx_vhost_path: /etc/nginx/sites-available +nginx_vhost_symlink_path: /etc/nginx/sites-enabled nginx_default_vhost_path: /etc/nginx/sites-enabled/default __nginx_user: "www-data"