mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d65cd3c5c | ||
|
|
9779555ac8 | ||
|
|
17905edf30 | ||
|
|
f2c6ec6c57 | ||
|
|
80e3cae22e | ||
|
|
3fdc16578c |
36
README.md
36
README.md
@@ -1,7 +1,7 @@
|
||||
Nginx for Debian Ansible role
|
||||
=============================
|
||||
|
||||
[](https://galaxy.ansible.com/list#/roles/4399) [](https://travis-ci.org/HanXHX/ansible-nginx)
|
||||
[](https://galaxy.ansible.com/list#/roles/4399) [](https://travis-ci.org/HanXHX/ansible-nginx)
|
||||
|
||||
Install and configure Nginx on Debian.
|
||||
|
||||
@@ -55,28 +55,32 @@ 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 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!)
|
||||
- `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`
|
||||
- `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
|
||||
(M): Mandatory
|
||||
(D): Depends other keys...
|
||||
|
||||
#### Templates
|
||||
|
||||
- `base`: static template
|
||||
- `dokuwiki`
|
||||
- `phalcon`: Phalcon PHP Framework
|
||||
- `php`: PHP base template. Can work with many frameworks/tools
|
||||
- `php_index`: Same as above. But you can only run index.php
|
||||
- `proxy`
|
||||
- `wordpress`
|
||||
- `_base`: static template
|
||||
- `_dokuwiki`
|
||||
- `_redirect`: should not be called explicitly
|
||||
- `_phalcon`: Phalcon PHP Framework
|
||||
- `_php`: PHP base template. Can work with many frameworks/tools
|
||||
- `_php_index`: Same as above. But you can only run index.php
|
||||
- `_proxy`
|
||||
- `_wordpress`
|
||||
|
||||
Templates works as parent-child.
|
||||
|
||||
@@ -92,7 +96,6 @@ You have many key added to vhost key:
|
||||
(O) : Optional
|
||||
(M) : Mandatory
|
||||
|
||||
|
||||
### Upstream management
|
||||
|
||||
- `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).
|
||||
|
||||
- `weight`
|
||||
- `max`fails`
|
||||
- `fail`timeout`
|
||||
- `max_fails`
|
||||
- `fail_timeout`
|
||||
- `backup`
|
||||
- `down`
|
||||
- `route`
|
||||
@@ -127,9 +130,7 @@ None
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
- hosts: servers
|
||||
roles:
|
||||
- { role: HanXHX.nginx }
|
||||
See [tests/test.yml](tests/test.yml).
|
||||
|
||||
License
|
||||
-------
|
||||
@@ -139,4 +140,5 @@ GPLv2
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
- Twitter: https://twitter.com/hanxhx
|
||||
- Twitter: [@hanxhx_](https://twitter.com/hanxhx_)
|
||||
|
||||
|
||||
3
Vagrantfile
vendored
3
Vagrantfile
vendored
@@ -7,7 +7,8 @@ Vagrant.configure("2") do |config|
|
||||
|
||||
vms = [
|
||||
[ "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|
|
||||
|
||||
@@ -10,7 +10,7 @@ nginx_log_dir: '/var/log/nginx'
|
||||
nginx_ssl_dir: '/etc/nginx/ssl'
|
||||
nginx_pid: '/run/nginx.pid'
|
||||
nginx_resolver:
|
||||
hosts: ['8.8.8.8', '8.8.4.4'] # OpenDNS
|
||||
hosts: ['8.8.8.8', '8.8.4.4']
|
||||
valid: '300'
|
||||
timeout: '5'
|
||||
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_sockets:
|
||||
- unix_socket: "/var/run/php5-fpm.sock"
|
||||
nginx_upstreams: []
|
||||
|
||||
#
|
||||
# Nginx configuration
|
||||
@@ -70,5 +71,7 @@ nginx_http:
|
||||
gzip_disable: '"msie6"'
|
||||
# etag: 'off'
|
||||
|
||||
#
|
||||
# Vhosts
|
||||
#
|
||||
nginx_vhosts: []
|
||||
nginx_upstreams: []
|
||||
|
||||
@@ -39,6 +39,3 @@
|
||||
- name: INCLUDE | Vhosts configuration
|
||||
include: vhost.yml
|
||||
|
||||
# TODO:
|
||||
# - Python
|
||||
# - Ruby (SHIT!)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
||||
template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf
|
||||
when: nginx_php
|
||||
notify: reload nginx
|
||||
|
||||
- name: TEMPLATE | Deploy other upstreams
|
||||
|
||||
@@ -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
|
||||
@@ -44,8 +46,7 @@
|
||||
# with_fileglob: "web/*"
|
||||
|
||||
- name: FILE | Delete vhosts
|
||||
file: dest=/etc/nginx/sites-enabled/{{ 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
|
||||
file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent
|
||||
with_items: nginx_vhosts
|
||||
notify: reload nginx
|
||||
when: item.delete is defined and item.delete
|
||||
@@ -63,10 +64,10 @@
|
||||
(item.delete is not defined or not item.delete)
|
||||
|
||||
- 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
|
||||
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)
|
||||
# file: dest=/etc/nginx/ssl/{{ item.name }} owner=root mode=0750 state=directory
|
||||
|
||||
@@ -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;
|
||||
|
||||
14
templates/etc/nginx/sites-available/_redirect.j2
Normal file
14
templates/etc/nginx/sites-available/_redirect.j2
Normal 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 %}
|
||||
@@ -50,6 +50,8 @@
|
||||
upstream_name: 'test'
|
||||
- name: 'deleted.local'
|
||||
delete: true
|
||||
- name: 'redirect-to.local'
|
||||
redirect_to: 'http://test.local'
|
||||
roles:
|
||||
- ../../
|
||||
post_tasks:
|
||||
|
||||
Reference in New Issue
Block a user