New feature on vhosts: "redirect_to"
parent
3fdc16578c
commit
80e3cae22e
|
@ -55,18 +55,20 @@ You can see many examples in: [tests/test.yml](tests/test.yml).
|
||||||
#### Common
|
#### Common
|
||||||
|
|
||||||
- `name`: (M) Domain or list of domain used.
|
- `name`: (M) Domain or list of domain used.
|
||||||
- `template`: (M) template used to create vhost. Optional if you set `delete` to true.
|
- `template`: (D) template used to create vhost. Optional if you set `delete` to true or using `redirect_tor`.
|
||||||
- `enable`: (O) Enable the vhost (default is true)
|
- `enable`: (O) Enable the vhost (default is true)
|
||||||
- `delete`: (O) Delete the vhost (default is false)
|
- `delete`: (O) Delete the vhost (default is false)
|
||||||
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
||||||
|
- `redirect_to`: (O) Redirect (302) all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
||||||
- `location`: (O) Add new custom locations (it does not overwrite!)
|
- `location`: (O) Add new custom locations (it does not overwrite!)
|
||||||
- `more`: (O) Add more custom infos.
|
- `more`: (O) Add more custom infos.
|
||||||
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
|
||||||
- `override_try_files`: (O) overrides default try\_files defined in template
|
- `override_try_files`: (O) overrides default try\_files defined in template
|
||||||
- `manage_local_content`: (O) Boolean. Set to false if you don't want to manage local content (images, css...). This option is useless if you use proxy `template`
|
- `manage_local_content`: (O) Boolean. Set to false if you don't want to manage local content (images, css...). This option is useless if you use proxy `template`
|
||||||
|
|
||||||
(O) : Optional
|
(O): Optional
|
||||||
(M) : Mandatory
|
(M): Mandatory
|
||||||
|
(D): Depends other keys...
|
||||||
|
|
||||||
#### Templates
|
#### Templates
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
when: >
|
when: >
|
||||||
item.root is not defined and
|
item.root is not defined and
|
||||||
(item.template is defined and item.template != '_proxy') and
|
(item.template is defined and item.template != '_proxy') and
|
||||||
(item.delete is not defined or not item.delete)
|
(item.delete is not defined or not item.delete) and
|
||||||
|
item.redirect_to is not defined
|
||||||
|
|
||||||
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
||||||
file: >
|
file: >
|
||||||
|
@ -29,11 +30,12 @@
|
||||||
when: >
|
when: >
|
||||||
item.root is not defined and
|
item.root is not defined and
|
||||||
(item.template is defined and item.template != '_proxy') and
|
(item.template is defined and item.template != '_proxy') and
|
||||||
(item.delete is not defined or not item.delete)
|
(item.delete is not defined or not item.delete) and
|
||||||
|
item.redirect_to is not defined
|
||||||
|
|
||||||
- name: TEMPLATE | Create vhosts
|
- name: TEMPLATE | Create vhosts
|
||||||
template: >
|
template: >
|
||||||
src=etc/nginx/sites-available/{{ item.template }}.j2
|
src=etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2
|
||||||
dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }}
|
dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }}
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
|
@ -13,11 +13,13 @@ server {
|
||||||
listen {{ port }};
|
listen {{ port }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
||||||
|
{% block root %}
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
{% else %}
|
{% else %}
|
||||||
root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public;
|
root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
index {{ item.index | default('index.html index.htm') }};
|
index {{ item.index | default('index.html index.htm') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -41,12 +43,12 @@ server {
|
||||||
{% block template_custom_location %}
|
{% block template_custom_location %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_local_content %}
|
||||||
|
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
||||||
location ~ /\.ht {
|
location ~ /\.ht {
|
||||||
deny all;
|
deny all;
|
||||||
}
|
}
|
||||||
|
|
||||||
{% block template_local_content %}
|
|
||||||
{% if item.manage_local_content is not defined or item.manage_local_content %}
|
|
||||||
location = /favicon.ico {
|
location = /favicon.ico {
|
||||||
expires 30d;
|
expires 30d;
|
||||||
access_log off;
|
access_log off;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
|
{% block root %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_index %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
return 302 {{ item.redirect_to }}$request_uri;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_local_content %}
|
||||||
|
{% endblock %}
|
|
@ -50,6 +50,8 @@
|
||||||
upstream_name: 'test'
|
upstream_name: 'test'
|
||||||
- name: 'deleted.local'
|
- name: 'deleted.local'
|
||||||
delete: true
|
delete: true
|
||||||
|
- name: 'redirect-to.local'
|
||||||
|
redirect_to: 'http://test.local'
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
post_tasks:
|
post_tasks:
|
||||||
|
|
Loading…
Reference in New Issue