6 Commits
1.0.8 ... 1.0.9

Author SHA1 Message Date
Emilien Mantel
0d65cd3c5c Add redirect_to_code in vhost 2015-12-01 16:40:34 +01:00
Emilien Mantel
9779555ac8 Few minor changes 2015-12-01 16:35:56 +01:00
Emilien Mantel
17905edf30 Begin Stretch support 2015-12-01 16:26:16 +01:00
Emilien Mantel
f2c6ec6c57 Travis badge on master branch 2015-12-01 15:52:10 +01:00
Emilien Mantel
80e3cae22e New feature on vhosts: "redirect_to" 2015-12-01 15:46:57 +01:00
Emilien Mantel
3fdc16578c Improve file deletions 2015-11-30 14:41:35 +01:00
9 changed files with 57 additions and 34 deletions

View File

@@ -1,7 +1,7 @@
Nginx for Debian Ansible role Nginx for Debian Ansible role
============================= =============================
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/list#/roles/4399) [![Build Status](https://travis-ci.org/HanXHX/ansible-nginx.svg)](https://travis-ci.org/HanXHX/ansible-nginx) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/list#/roles/4399) [![Build Status](https://travis-ci.org/HanXHX/ansible-nginx.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-nginx)
Install and configure Nginx on Debian. Install and configure Nginx on Debian.
@@ -55,28 +55,32 @@ 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 all requests to this domain. Please set scheme (http:// or https:// or $sheme).
- `redirect_to_code`: Redirect code (default: 302)
- `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 or `redirect_to` feature.
(O): Optional (O): Optional
(M): Mandatory (M): Mandatory
(D): Depends other keys...
#### Templates #### Templates
- `base`: static template - `_base`: static template
- `dokuwiki` - `_dokuwiki`
- `phalcon`: Phalcon PHP Framework - `_redirect`: should not be called explicitly
- `php`: PHP base template. Can work with many frameworks/tools - `_phalcon`: Phalcon PHP Framework
- `php_index`: Same as above. But you can only run index.php - `_php`: PHP base template. Can work with many frameworks/tools
- `proxy` - `_php_index`: Same as above. But you can only run index.php
- `wordpress` - `_proxy`
- `_wordpress`
Templates works as parent-child. Templates works as parent-child.
@@ -92,7 +96,6 @@ You have many key added to vhost key:
(O) : Optional (O) : Optional
(M) : Mandatory (M) : Mandatory
### Upstream management ### Upstream management
- `nginx_upstreams`: List of dict. An upstream has few keys. See bellow. - `nginx_upstreams`: List of dict. An upstream has few keys. See bellow.
@@ -112,8 +115,8 @@ You must set a `path`. For example: *192.168.0.50:8080* or *unix:/tmp/my.sock*.
All this params are optional. You should see [Nginx upstream doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html). All this params are optional. You should see [Nginx upstream doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
- `weight` - `weight`
- `max`fails` - `max_fails`
- `fail`timeout` - `fail_timeout`
- `backup` - `backup`
- `down` - `down`
- `route` - `route`
@@ -127,9 +130,7 @@ None
Example Playbook Example Playbook
---------------- ----------------
- hosts: servers See [tests/test.yml](tests/test.yml).
roles:
- { role: HanXHX.nginx }
License License
------- -------
@@ -139,4 +140,5 @@ GPLv2
Author Information Author Information
------------------ ------------------
- Twitter: https://twitter.com/hanxhx - Twitter: [@hanxhx_](https://twitter.com/hanxhx_)

3
Vagrantfile vendored
View File

@@ -7,7 +7,8 @@ Vagrant.configure("2") do |config|
vms = [ vms = [
[ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.27" ], [ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.27" ],
[ "debian-jessie", "deb/jessie-amd64", "192.168.33.28" ] [ "debian-jessie", "deb/jessie-amd64", "192.168.33.28" ],
[ "debian-stretch", "sharlak/debian_stretch_64", "192.168.33.29" ]
] ]
config.vm.provider "virtualbox" do |v| config.vm.provider "virtualbox" do |v|

View File

@@ -10,7 +10,7 @@ nginx_log_dir: '/var/log/nginx'
nginx_ssl_dir: '/etc/nginx/ssl' nginx_ssl_dir: '/etc/nginx/ssl'
nginx_pid: '/run/nginx.pid' nginx_pid: '/run/nginx.pid'
nginx_resolver: nginx_resolver:
hosts: ['8.8.8.8', '8.8.4.4'] # OpenDNS hosts: ['8.8.8.8', '8.8.4.4']
valid: '300' valid: '300'
timeout: '5' timeout: '5'
nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#error_log
@@ -25,6 +25,7 @@ nginx_dh_length: 2048
nginx_php: false nginx_php: false
nginx_php_sockets: nginx_php_sockets:
- unix_socket: "/var/run/php5-fpm.sock" - unix_socket: "/var/run/php5-fpm.sock"
nginx_upstreams: []
# #
# Nginx configuration # Nginx configuration
@@ -70,5 +71,7 @@ nginx_http:
gzip_disable: '"msie6"' gzip_disable: '"msie6"'
# etag: 'off' # etag: 'off'
#
# Vhosts
#
nginx_vhosts: [] nginx_vhosts: []
nginx_upstreams: []

View File

@@ -39,6 +39,3 @@
- name: INCLUDE | Vhosts configuration - name: INCLUDE | Vhosts configuration
include: vhost.yml include: vhost.yml
# TODO:
# - Python
# - Ruby (SHIT!)

View File

@@ -2,6 +2,7 @@
- name: TEMPLATE | Deploy PHP upstream to Nginx - name: TEMPLATE | Deploy PHP upstream to Nginx
template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf
when: nginx_php
notify: reload nginx notify: reload nginx
- name: TEMPLATE | Deploy other upstreams - name: TEMPLATE | Deploy other upstreams

View File

@@ -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
@@ -44,8 +46,7 @@
# with_fileglob: "web/*" # with_fileglob: "web/*"
- name: FILE | Delete vhosts - name: FILE | Delete vhosts
file: dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent
file: dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent
with_items: nginx_vhosts with_items: nginx_vhosts
notify: reload nginx notify: reload nginx
when: item.delete is defined and item.delete when: item.delete is defined and item.delete
@@ -63,10 +64,10 @@
(item.delete is not defined or not item.delete) (item.delete is not defined or not item.delete)
- name: FILE | Disable vhosts - name: FILE | Disable vhosts
file: dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent file: path=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent
with_items: nginx_vhosts with_items: nginx_vhosts
notify: reload nginx notify: reload nginx
when: item.enable is defined and not item.enable when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete)
#- name: FILE | Create ssl dir per vhost (if needed) #- name: FILE | Create ssl dir per vhost (if needed)
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory # file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory

View File

@@ -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;

View File

@@ -0,0 +1,14 @@
{% extends "_base.j2" %}
{% block root %}
{% endblock %}
{% block template_index %}
{% endblock %}
{% block template_try_files %}
return {{ item.redirect_to_code | default('302') }} {{ item.redirect_to }}$request_uri;
{% endblock %}
{% block template_local_content %}
{% endblock %}

View File

@@ -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: