mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d56fc249d | ||
|
|
bfe4a315f9 | ||
|
|
9fcba824f5 | ||
|
|
d1dbdb83d4 | ||
|
|
bee0cb9a66 | ||
|
|
6be44c7da8 | ||
|
|
a0a6e35a3a | ||
|
|
f57ab08594 | ||
|
|
d26a6f26f5 | ||
|
|
97c3d2e169 | ||
|
|
c2644d4e5d | ||
|
|
70529e223d | ||
|
|
803f435b48 | ||
|
|
710b3ad53b | ||
|
|
bf1b9950cb | ||
|
|
050c16401f | ||
|
|
eaf4032bc0 | ||
|
|
63fee94d90 | ||
|
|
a50d7e8774 | ||
|
|
96bbc47d27 | ||
|
|
a9a898e910 | ||
|
|
edb36acd5d | ||
|
|
fb0b210d45 | ||
|
|
a02b44a2f0 | ||
|
|
95e2cb5f12 |
10
.travis.yml
10
.travis.yml
@@ -2,10 +2,12 @@ env:
|
|||||||
- PLATFORM=debian-wheezy
|
- PLATFORM=debian-wheezy
|
||||||
- PLATFORM=debian-jessie
|
- PLATFORM=debian-jessie
|
||||||
|
|
||||||
sudo: true
|
sudo: required
|
||||||
|
|
||||||
install:
|
language: python
|
||||||
- curl -sLo - http://j.mp/install-travis-docker | sh -xe
|
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./run 'docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM'
|
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
|
||||||
|
|||||||
66
README.md
66
README.md
@@ -1,11 +1,11 @@
|
|||||||
Nginx for Debian Ansible role
|
Nginx for Debian Ansible role
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
[](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.
|
Install and configure Nginx on Debian.
|
||||||
|
|
||||||
This role is not production ready. SSL management wille come later.
|
SSL management will come later.
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
@@ -44,20 +44,26 @@ Socket:
|
|||||||
- `nginx_worker_processes`
|
- `nginx_worker_processes`
|
||||||
- `nginx_events`: key/value in events block
|
- `nginx_events`: key/value in events block
|
||||||
- `nginx_http`: key/value in http block
|
- `nginx_http`: key/value in http block
|
||||||
|
- `nginx_pid`: daemon pid file
|
||||||
|
|
||||||
### Vhost management
|
### Vhost management
|
||||||
|
|
||||||
|
You can see many examples in: [tests/test.yml](tests/test.yml).
|
||||||
|
|
||||||
- `nginx_vhosts`: List of dict. A vhost has few keys. See bellow.
|
- `nginx_vhosts`: List of dict. A vhost has few keys. See bellow.
|
||||||
|
|
||||||
####
|
#### Common
|
||||||
|
|
||||||
- `name`: (M) List of domain used. The first occurence is the most important!
|
- `name`: (M) Domain or list of domain used.
|
||||||
- `template`: (M) template used to create vhost
|
- `template`: (M) template used to create vhost. Optional if you set `delete` to true.
|
||||||
- `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
|
||||||
- `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)
|
||||||
|
- `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
|
(O) : Optional
|
||||||
(M) : Mandatory
|
(M) : Mandatory
|
||||||
@@ -65,13 +71,53 @@ Socket:
|
|||||||
#### Templates
|
#### Templates
|
||||||
|
|
||||||
- `base`: static template
|
- `base`: static template
|
||||||
- `php`: PHP base template. Can work with many frameworks/tools.
|
|
||||||
- `wordpress`
|
|
||||||
- `dokuwiki`
|
- `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`
|
||||||
|
|
||||||
Templates works as parent-child.
|
Templates works as parent-child.
|
||||||
|
|
||||||
You can see many examples in: [tests/test.yml](tests/test.yml).
|
#### About proxy template
|
||||||
|
|
||||||
|
Proxy template allow you to use Nginx as reverse proxy. Usefull when you have application serveur such as Redmine, Jenkins...
|
||||||
|
|
||||||
|
You have many key added to vhost key:
|
||||||
|
|
||||||
|
- `upstream_name`: (O) upstream name used to pass proxy
|
||||||
|
- `proxy_params`: (M) list of raw params passed to the vhost
|
||||||
|
|
||||||
|
(O) : Optional
|
||||||
|
(M) : Mandatory
|
||||||
|
|
||||||
|
|
||||||
|
### Upstream management
|
||||||
|
|
||||||
|
- `nginx_upstreams`: List of dict. An upstream has few keys. See bellow.
|
||||||
|
|
||||||
|
Note: Few params are unavailable on old Nginx version. But this role don't put it if your version is too old!
|
||||||
|
|
||||||
|
#### Upstream params
|
||||||
|
|
||||||
|
- `name`: upstream name. Can be use in vhost with *proxy_pass http://upstream_name*
|
||||||
|
- `params`: list of param (hash, zone...)
|
||||||
|
- `servers`: each upstream MUST have at least 1 server
|
||||||
|
|
||||||
|
#### Server params
|
||||||
|
|
||||||
|
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`
|
||||||
|
- `backup`
|
||||||
|
- `down`
|
||||||
|
- `route`
|
||||||
|
- `slow`start`
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
@@ -93,6 +139,4 @@ GPLv2
|
|||||||
Author Information
|
Author Information
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
- You can find many other roles in my GitHub "lab": https://github.com/HanXHX/my-ansible-playbooks
|
- Twitter: https://twitter.com/hanxhx
|
||||||
- All issues, pull-request are welcome :)
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ nginx_apt_package: nginx-full
|
|||||||
nginx_root: "/srv/www"
|
nginx_root: "/srv/www"
|
||||||
nginx_log_dir: '/var/log/nginx'
|
nginx_log_dir: '/var/log/nginx'
|
||||||
nginx_ssl_dir: '/etc/nginx/ssl'
|
nginx_ssl_dir: '/etc/nginx/ssl'
|
||||||
|
nginx_pid: '/run/nginx.pid'
|
||||||
nginx_resolver:
|
nginx_resolver:
|
||||||
hosts: ['208.67.222.222', '208.67.220.220'] # OpenDNS
|
hosts: ['8.8.8.8', '8.8.4.4'] # OpenDNS
|
||||||
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
|
||||||
@@ -70,3 +71,4 @@ nginx_http:
|
|||||||
# etag: 'off'
|
# etag: 'off'
|
||||||
|
|
||||||
nginx_vhosts: []
|
nginx_vhosts: []
|
||||||
|
nginx_upstreams: []
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
---
|
||||||
- name: restart nginx
|
|
||||||
action: service name=nginx state=restarted enabled=yes
|
|
||||||
|
|
||||||
- name: reload nginx
|
- name: reload nginx
|
||||||
action: service name=nginx state=reloaded enabled=yes
|
action: service name=nginx state=reloaded enabled=yes
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ galaxy_info:
|
|||||||
description: Nginx for Debian
|
description: Nginx for Debian
|
||||||
company:
|
company:
|
||||||
license: GPLv2
|
license: GPLv2
|
||||||
min_ansible_version: 1.2
|
min_ansible_version: 1.6
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy nginx.conf
|
- name: TEMPLATE | Deploy nginx.conf
|
||||||
template: src=etc/nginx/nginx.conf.j2 dest=/etc/nginx/nginx.conf validate= "nginx -t"
|
template: >
|
||||||
notify: restart nginx
|
src=etc/nginx/nginx.conf.j2
|
||||||
|
dest=/etc/nginx/nginx.conf
|
||||||
|
notify: reload nginx
|
||||||
|
|
||||||
- name: FILE | Create /etc/nginx/helpers
|
- name: FILE | Create /etc/nginx/helpers
|
||||||
file: dest=/etc/nginx/helpers owner=root mode=0755 state=directory
|
file: dest=/etc/nginx/helpers owner=root mode=0755 state=directory
|
||||||
@@ -24,7 +26,9 @@
|
|||||||
# creates: "{{ nginx_dh_path }}"
|
# creates: "{{ nginx_dh_path }}"
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy all helpers
|
- name: TEMPLATE | Deploy all helpers
|
||||||
template: src={{ item }} dest=/etc/nginx/helpers/{{ item | basename | regex_replace('\.j2$','') }}
|
template: >
|
||||||
|
src={{ item }}
|
||||||
|
dest=/etc/nginx/helpers/{{ item | basename | regex_replace('\.j2$','') }}
|
||||||
with_fileglob: '../templates/etc/nginx/helpers/*.j2'
|
with_fileglob: '../templates/etc/nginx/helpers/*.j2'
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,7 @@
|
|||||||
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
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: TEMPLATE | Deploy other upstreams
|
||||||
|
template: src=etc/nginx/upstream/upstream.conf.j2 dest=/etc/nginx/conf.d/upstream-{{ item.name }}.conf
|
||||||
|
with_items: nginx_upstreams
|
||||||
|
notify: reload nginx
|
||||||
|
|||||||
@@ -1,19 +1,40 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- name: FILE | Create root directory
|
||||||
|
file: >
|
||||||
|
path={{ nginx_root }}
|
||||||
|
state=directory
|
||||||
|
|
||||||
- name: FILE | Create root folders (foreach nginx_vhosts)
|
- name: FILE | Create root folders (foreach nginx_vhosts)
|
||||||
file: >
|
file: >
|
||||||
path={{ nginx_root }}/{{ item.name[0] }}/public
|
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}
|
||||||
state=directory
|
state=directory
|
||||||
owner={{ item.owner | default('www-data') }}
|
owner={{ item.owner | default('www-data') }}
|
||||||
group={{ item.group | default('www-data') }}
|
group={{ item.group | default('www-data') }}
|
||||||
mode={{ item.mode | default('0755') }}
|
mode={{ item.mode | default('0755') }}
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
when: item.root is not defined
|
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)
|
||||||
|
|
||||||
|
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
||||||
|
file: >
|
||||||
|
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public
|
||||||
|
state=directory
|
||||||
|
owner={{ item.owner | default('www-data') }}
|
||||||
|
group={{ item.group | default('www-data') }}
|
||||||
|
mode={{ item.mode | default('0755') }}
|
||||||
|
with_items: nginx_vhosts
|
||||||
|
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)
|
||||||
|
|
||||||
- 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 }}.j2
|
||||||
dest=/etc/nginx/sites-available/{{ 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
|
||||||
when: item.delete is not defined or not item.delete
|
when: item.delete is not defined or not item.delete
|
||||||
@@ -23,16 +44,16 @@
|
|||||||
# with_fileglob: "web/*"
|
# with_fileglob: "web/*"
|
||||||
|
|
||||||
- name: FILE | Delete vhosts
|
- name: FILE | Delete vhosts
|
||||||
file: dest=/etc/nginx/sites-enabled/{{ item.name[0] }} state=absent
|
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[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
|
||||||
|
|
||||||
- name: FILE | Enable vhosts
|
- name: FILE | Enable vhosts
|
||||||
file: >
|
file: >
|
||||||
src=/etc/nginx/sites-available/{{ item.name[0] }}
|
src=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }}
|
||||||
dest=/etc/nginx/sites-enabled/{{ item.name[0] }}
|
dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }}
|
||||||
state=link
|
state=link
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
@@ -42,7 +63,7 @@
|
|||||||
(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[0] }} state=absent
|
file: dest=/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
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
user {{ nginx_user }};
|
user {{ nginx_user }};
|
||||||
worker_processes {{ nginx_worker_processes }};
|
worker_processes {{ nginx_worker_processes }};
|
||||||
pid /run/nginx.pid;
|
pid {{ nginx_pid }};
|
||||||
|
|
||||||
events {
|
events {
|
||||||
{% for key, value in nginx_events.iteritems() %}
|
{% for key, value in nginx_events.iteritems() %}
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ server {
|
|||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }};
|
listen {{ port }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {{ item.name | join(' ') }};
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
{% else %}
|
{% else %}
|
||||||
root {{ nginx_root }}/{{ item.name[0] }}/public;
|
root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
index {{ item.index | default('index.html index.htm') }};
|
index {{ item.index | default('index.html index.htm') }};
|
||||||
@@ -24,15 +24,17 @@ server {
|
|||||||
|
|
||||||
{% if item.more is defined and item.more is iterable %}
|
{% if item.more is defined and item.more is iterable %}
|
||||||
{% for line in item.more %}
|
{% for line in item.more %}
|
||||||
{{ item.more }}
|
{{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not __location.has_key('/') %}
|
||||||
location / {
|
location / {
|
||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files $uri $uri/ =404;
|
try_files {{ override_try_files | default('$uri $uri/ =404') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
}
|
}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -43,6 +45,8 @@ server {
|
|||||||
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;
|
||||||
@@ -53,6 +57,8 @@ server {
|
|||||||
expires 30d;
|
expires 30d;
|
||||||
log_not_found off;
|
log_not_found off;
|
||||||
}
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% if __location is iterable and __location | length > 0 %}
|
{% if __location is iterable and __location | length > 0 %}
|
||||||
# --> Custom locations
|
# --> Custom locations
|
||||||
|
|||||||
@@ -4,15 +4,18 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files $uri $uri/ /index.php;
|
try_files {{ override_try_files | default('$uri $uri/ /index.php') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
fastcgi_pass php;
|
fastcgi_pass php;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{# TODO: fastcgi_intercept_errors {{ item.php.intercept_errors | default('on') }}; #}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
fastcgi_intercept_errors on;
|
{% for param in item.upstream_params %}
|
||||||
|
{{ param }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
24
templates/etc/nginx/sites-available/_php_index.j2
Normal file
24
templates/etc/nginx/sites-available/_php_index.j2
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
location = /index.php {
|
||||||
|
fastcgi_pass php;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
|
{% for param in item.upstream_params %}
|
||||||
|
{{ param }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||||
|
include fastcgi_params;
|
||||||
|
{% else %}
|
||||||
|
include fastcgi.conf;
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_custom_location %}
|
||||||
|
location ~ \.(php\d?|phtml)$ {
|
||||||
|
return 403;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
23
templates/etc/nginx/sites-available/_proxy.j2
Normal file
23
templates/etc/nginx/sites-available/_proxy.j2
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
|
||||||
|
proxy_pass http://{{ item.upstream_name }};
|
||||||
|
proxy_read_timeout 90;
|
||||||
|
|
||||||
|
{#proxy_redirect http://{{ upstream.name }} https://jenkins.domain.tld;#}
|
||||||
|
|
||||||
|
{% if item.proxy_params is defined and item.proxy_params is iterable %}
|
||||||
|
{% for param in item.proxy_params %}
|
||||||
|
{{ param }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{# We flush the default local content (locations) #}
|
||||||
|
{% block template_local_content %}
|
||||||
|
{% endblock %}
|
||||||
19
templates/etc/nginx/upstream/upstream.conf.j2
Normal file
19
templates/etc/nginx/upstream/upstream.conf.j2
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{%- macro s(key, value, is_bool, min_version) %}
|
||||||
|
{% if nginx_version.stdout | version_compare(min_version, 'ge') %}
|
||||||
|
{% if is_bool and value %} {{ key }}{% elif not is_bool %} {{ key }}={{ value }}{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{%- endmacro -%}
|
||||||
|
#
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
#
|
||||||
|
|
||||||
|
upstream {{ item.name }} {
|
||||||
|
{% for server in item.servers %}
|
||||||
|
server {{ server.path }}{% for p in nginx_upstream_server_params if server[p.key] is defined %}{{ s(p.key, server[p.key] | default(p.default), p.is_bool | default(false), p.min_version | default('0.0.1')) }}{% endfor %};
|
||||||
|
{% endfor %}
|
||||||
|
{% if item.params is defined and item.params is iterable %}
|
||||||
|
{% for param in item.params %}
|
||||||
|
{{ param }};
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
@@ -2,5 +2,3 @@ FROM williamyeh/ansible:debian8-onbuild
|
|||||||
|
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
CMD ["sh", "tests/test.sh"]
|
CMD ["sh", "tests/test.sh"]
|
||||||
|
|
||||||
EXPOSE 6379
|
|
||||||
|
|||||||
@@ -2,5 +2,3 @@ FROM williamyeh/ansible:debian7-onbuild
|
|||||||
|
|
||||||
RUN apt-get update
|
RUN apt-get update
|
||||||
CMD ["sh", "tests/test.sh"]
|
CMD ["sh", "tests/test.sh"]
|
||||||
|
|
||||||
EXPOSE 6379
|
|
||||||
|
|||||||
@@ -8,42 +8,71 @@
|
|||||||
- curl
|
- curl
|
||||||
vars:
|
vars:
|
||||||
nginx_php: true
|
nginx_php: true
|
||||||
|
nginx_upstreams:
|
||||||
|
- name: 'test'
|
||||||
|
servers:
|
||||||
|
- path: '127.0.0.1:80'
|
||||||
|
max_conns: 150
|
||||||
|
weight: 10
|
||||||
|
down: false
|
||||||
nginx_vhosts:
|
nginx_vhosts:
|
||||||
- name:
|
- name:
|
||||||
- 'test.local'
|
- 'test.local'
|
||||||
- 'test-alias.local'
|
- 'test-alias.local'
|
||||||
- 'test2-alias.local'
|
- 'test2-alias.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
|
override_try_files: '$uri $uri index.htm index.html'
|
||||||
|
manage_local_content: false
|
||||||
more:
|
more:
|
||||||
- 'etag off;'
|
- 'autoindex off;'
|
||||||
location:
|
location:
|
||||||
'/test':
|
'/test':
|
||||||
- 'return 403;'
|
- 'return 403;'
|
||||||
'/gunther':
|
'/gunther':
|
||||||
- 'return 404;'
|
- 'return 404;'
|
||||||
- name:
|
- name: 'test-location.local'
|
||||||
- 'test-php.local'
|
template: '_base'
|
||||||
|
location:
|
||||||
|
'/':
|
||||||
|
- 'alias /var/tmp;'
|
||||||
|
- name: 'test-php.local'
|
||||||
|
upstream_params:
|
||||||
|
- 'fastcgi_param FOO bar;'
|
||||||
redirect_from:
|
redirect_from:
|
||||||
- 'www.test-php.local'
|
- 'www.test-php.local'
|
||||||
template: '_php'
|
template: '_php'
|
||||||
- name:
|
- name: 'test-php-index.local'
|
||||||
- 'deleted.local'
|
template: '_php_index'
|
||||||
template: '_base'
|
- name: 'test-proxy.local'
|
||||||
|
listen:
|
||||||
|
- 8080
|
||||||
|
template: '_proxy'
|
||||||
|
upstream_name: 'test'
|
||||||
|
- name: 'deleted.local'
|
||||||
delete: true
|
delete: true
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
post_tasks:
|
post_tasks:
|
||||||
- name: -- Add PHP file --
|
- name: -- Add PHP file --
|
||||||
copy: dest="{{ nginx_root }}/test-php.local/public/index.php" content="<?php phpinfo();"
|
copy: dest="{{ nginx_root }}/{{ item }}/public/index.php" content="<?php phpinfo();"
|
||||||
|
with_items: ['test-php.local', 'test-php-index.local']
|
||||||
- name: -- Add HTML file --
|
- name: -- Add HTML file --
|
||||||
copy: dest="{{ nginx_root }}/test.local/public/index.html" content="Index HTML test OK\n"
|
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
|
||||||
|
with_items: ['{{ nginx_root }}/test.local/public', '/var/tmp']
|
||||||
- name: -- VERIFY VHOSTS --
|
- name: -- VERIFY VHOSTS --
|
||||||
shell: "curl -H 'Host: {{ item.name[0] }}' http://127.0.0.1/"
|
command: "curl -H 'Host: {{ item.name if item.name is string else item.name[0] }}' http://127.0.0.1{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
when: item.delete is undefined or not item.delete
|
when: item.delete is undefined or not item.delete
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
- name: -- VERIFY FORBIDDEN --
|
||||||
|
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
|
||||||
|
register: f
|
||||||
|
failed_when: f.stdout.find('403 Forbidden') == -1
|
||||||
|
changed_when: false
|
||||||
- name: -- VERIFY REDIRECT VHOSTS --
|
- name: -- VERIFY REDIRECT VHOSTS --
|
||||||
shell: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
|
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
|
||||||
with_items: nginx_vhosts
|
with_items: nginx_vhosts
|
||||||
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
|
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
register: r
|
||||||
|
failed_when: r.stdout.find('301 Moved Permanently') == -1
|
||||||
|
|||||||
@@ -1 +1,25 @@
|
|||||||
nginx_dh_path: /etc/nginx/ssl/dhparams.pem
|
nginx_dh_path: /etc/nginx/ssl/dhparams.pem
|
||||||
|
|
||||||
|
nginx_upstream_server_params:
|
||||||
|
- key: 'weight'
|
||||||
|
default: 1
|
||||||
|
- key: 'max_fails'
|
||||||
|
default: 1
|
||||||
|
- key: 'fail_timeout'
|
||||||
|
default: '10s'
|
||||||
|
- key: 'backup'
|
||||||
|
is_bool: true
|
||||||
|
- key: 'down'
|
||||||
|
is_bool: true
|
||||||
|
default: false
|
||||||
|
- key: 'route'
|
||||||
|
default: 'configuration_error'
|
||||||
|
- key: 'slow_start'
|
||||||
|
default: 0
|
||||||
|
# Nginx Plus only
|
||||||
|
# - key: 'max_conns'
|
||||||
|
# default: 0
|
||||||
|
# min_version: '1.5.9'
|
||||||
|
# - key: 'resolve'
|
||||||
|
# is_bool: true
|
||||||
|
# min_version: '1.5.12'
|
||||||
|
|||||||
Reference in New Issue
Block a user