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
 | 
			
		||||
 | 
			
		||||
  - `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)
 | 
			
		||||
  - `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_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!)
 | 
			
		||||
  - `more`: (O) Add more custom infos.
 | 
			
		||||
  - `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
 | 
			
		||||
  - `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
 | 
			
		||||
(M) : Mandatory
 | 
			
		||||
(O): Optional
 | 
			
		||||
(M): Mandatory
 | 
			
		||||
(D): Depends other keys...
 | 
			
		||||
 | 
			
		||||
#### Templates
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,8 @@
 | 
			
		|||
  when: >
 | 
			
		||||
    item.root is not defined 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)
 | 
			
		||||
  file: >
 | 
			
		||||
| 
						 | 
				
			
			@ -29,11 +30,12 @@
 | 
			
		|||
  when: >
 | 
			
		||||
    item.root is not defined 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
 | 
			
		||||
  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] }}
 | 
			
		||||
  with_items: nginx_vhosts
 | 
			
		||||
  notify: reload nginx
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,11 +13,13 @@ server {
 | 
			
		|||
	listen {{ port }};
 | 
			
		||||
{% endfor %}
 | 
			
		||||
	server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
 | 
			
		||||
{% block root %}
 | 
			
		||||
{% if item.root is defined %}
 | 
			
		||||
	root {{ item.root }};
 | 
			
		||||
{% else %}
 | 
			
		||||
	root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public;
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
{% block template_index %}
 | 
			
		||||
	index {{ item.index | default('index.html index.htm') }};
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			@ -41,12 +43,12 @@ server {
 | 
			
		|||
{% block template_custom_location %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block template_local_content %}
 | 
			
		||||
{% if item.manage_local_content is not defined or item.manage_local_content %}
 | 
			
		||||
	location ~ /\.ht {
 | 
			
		||||
		deny all;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
{% block template_local_content %}
 | 
			
		||||
{% if item.manage_local_content is not defined or item.manage_local_content %}
 | 
			
		||||
	location = /favicon.ico {
 | 
			
		||||
		expires 30d;
 | 
			
		||||
		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'
 | 
			
		||||
      - name: 'deleted.local'
 | 
			
		||||
        delete: true
 | 
			
		||||
      - name: 'redirect-to.local'
 | 
			
		||||
        redirect_to: 'http://test.local'
 | 
			
		||||
  roles:
 | 
			
		||||
    - ../../
 | 
			
		||||
  post_tasks:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue