mirror of
https://github.com/geerlingguy/ansible-role-nginx.git
synced 2025-02-14 00:52:04 +01:00
Issue #95: Add support for setting template on a per vhost basis
This commit is contained in:
parent
072001bed3
commit
5e41c6b1f9
16
README.md
16
README.md
@ -27,6 +27,7 @@ A list of vhost definitions (server blocks) for Nginx virtual hosts. Each entry
|
||||
access_log: ""
|
||||
error_log: ""
|
||||
state: "present"
|
||||
template: "{{ nginx_vhost_template }}"
|
||||
extra_parameters: |
|
||||
location ~ \.php$ {
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
@ -130,6 +131,21 @@ nginx_conf_template: "nginx.conf.j2"
|
||||
nginx_vhost_template: "vhost.j2"
|
||||
```
|
||||
|
||||
If necessary you can also set the template on a per vhost basis.
|
||||
|
||||
```yaml
|
||||
nginx_vhosts:
|
||||
- listen: "80 default_server"
|
||||
server_name: "site1.example.com"
|
||||
root: "/var/www/site1.example.com"
|
||||
index: "index.php index.html index.htm"
|
||||
template: "{{ playbook_dir }}/templates/site1.example.com.vhost.j2"
|
||||
- server_name: "site2.example.com"
|
||||
root: "/var/www/site2.example.com"
|
||||
index: "index.php index.html index.htm"
|
||||
template: "{{ playbook_dir }}/templates/site2.example.com.vhost.j2"
|
||||
```
|
||||
|
||||
You can either copy and modify the provided template, or extend it with [Jinja2 template inheritance](http://jinja.pocoo.org/docs/2.9/templates/#template-inheritance) and override the specific template block you need to change.
|
||||
|
||||
### Example: Configure gzip in nginx configuration
|
||||
|
@ -65,6 +65,7 @@ nginx_vhosts: []
|
||||
# access_log: ""
|
||||
# error_log: ""
|
||||
# extra_parameters: "" # Can be used to add extra config blocks (multiline).
|
||||
# template: "" # Can be used to override the `nginx_vhost_template` per host.
|
||||
# state: "absent" # To remove the vhost configuration.
|
||||
|
||||
nginx_upstreams: []
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
- name: Add managed vhost config files.
|
||||
template:
|
||||
src: "{{ nginx_vhost_template }}"
|
||||
src: "{{ item.template|default(nginx_vhost_template) }}"
|
||||
dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
|
||||
force: yes
|
||||
owner: root
|
||||
|
Loading…
Reference in New Issue
Block a user