72 Commits
1.1.0 ... 1.3.1

Author SHA1 Message Date
Emilien Mantel
a2e6e98436 Add new feature: nginx_fastcgi_fix_realpath 2016-08-30 17:14:34 +02:00
E Mantel
fc44b704cf Merge pull request #22 from HanXHX/vhost_state
Vhost state
2016-08-30 12:28:44 +02:00
Emilien Mantel
cf662acdd7 Fix condition when creating vhosts 2016-08-30 11:18:14 +02:00
Emilien Mantel
34c8d1926f Vhost state (closes #19) 2016-08-30 11:06:38 +02:00
Emilien Mantel
634d88874f Backward compatibility with nginx_php variable 2016-08-30 10:52:28 +02:00
Emilien Mantel
5e254331c4 manage php upstream version (styles) on vhost 2016-08-26 12:14:54 +02:00
Emilien Mantel
3ab8e0391c Disable tests for owncloud (fix later) 2016-08-25 18:19:07 +02:00
Emilien Mantel
aac33b7376 better vhost for owncloud 2016-08-11 13:03:56 +02:00
Emilien Mantel
88c6c5a043 Manages PHP minor versions 2016-08-11 11:30:26 +02:00
Emilien Mantel
a9ad41b40f Fix more block for owncloud 2016-08-11 11:09:43 +02:00
Emilien Mantel
d26b2b9a49 Fix owncloud root 2016-08-11 10:59:44 +02:00
Emilien Mantel
b17acac4c4 Tests packages on Debian 2016-08-11 10:48:12 +02:00
Emilien Mantel
c160640c7f Force latest version of openssl when uses nginx from backports 2016-08-11 10:36:50 +02:00
Emilien Mantel
887219f86c Force install OpenSSL from backports when nginx uses backports 2016-08-11 10:25:45 +02:00
Emilien Mantel
76c02abf47 Fix owncloud js (from php) and add tests 2016-08-11 09:38:09 +02:00
Emilien Mantel
26c93c9315 Add owncloud and prevent nginx from dotdeb 2016-08-10 21:29:03 +02:00
Emilien Mantel
8fb3829860 Drop Wheezy support in IC 2016-08-09 16:12:54 +02:00
Emilien Mantel
e4b5bb2a32 Support many php versions (php7) + drop wheezy support 2016-08-09 16:02:09 +02:00
Emilien Mantel
af3930a58a New feature: upstream state (remove upstream if needed) 2016-05-11 17:21:52 +02:00
Emilien Mantel
4dcb5f44c6 Don't need any inventory file for tests 2016-03-23 17:27:59 +01:00
Emilien Mantel
1204dbacd1 [FreeBSD] Enable nginx service 2016-03-15 23:12:17 +01:00
Emilien Mantel
3087154335 [FreeBSD] restart nginx on vhost config changed 2016-03-15 23:00:55 +01:00
Emilien Mantel
72edbe8656 [FreeBSD] Force create log dir 2016-03-15 22:49:19 +01:00
E Mantel
66b2ac238c README: Change URL in galaxy 2016-03-15 19:48:00 +01:00
Emilien Mantel
d49e41652c Update cipher list (from https://cipherli.st/) 2016-03-15 17:59:48 +01:00
Emilien Mantel
9b19231d8b use headers instead of more 2016-03-15 17:15:46 +01:00
Emilien Mantel
80d1d82acc Fix handler (didn't reload service after nginx -t) 2016-03-15 17:15:11 +01:00
Emilien Mantel
5445d66172 Add a wrapper: test configuration before reloading (better debugging) 2016-03-15 15:57:46 +01:00
Emilien Mantel
9a5afd09fa Force X-Frame-Options SAMEORIGIN for Nagios (closes #17) 2016-03-15 15:46:49 +01:00
Emilien Mantel
96e406c791 always directive managed for add_header option 2016-03-15 15:30:22 +01:00
Emilien Mantel
02994af5ee Default headers with always directive 2016-03-15 15:01:58 +01:00
Emilien Mantel
ee79ec9845 SSL helper can be disabled 2016-03-15 12:16:57 +01:00
Emilien Mantel
2ba906be2e Add custom headers in vhost (moved from ssl helpers) 2016-03-15 10:51:14 +01:00
Emilien Mantel
d223f8b144 Add a check for HTTPS redirect 2016-03-15 09:22:01 +01:00
Emilien Mantel
8f837de390 Avoid double / in redirect_https 2016-03-15 09:08:52 +01:00
Emilien Mantel
aa4bc8d6a7 Move to new galaxy version 2016-03-14 19:39:11 +01:00
Emilien Mantel
2fcf7fa701 Delete useless files 2016-03-14 19:37:25 +01:00
Emilien Mantel
91686fc266 doc minor fix 2016-03-14 19:27:51 +01:00
Emilien Mantel
5e493c15ac Fix deprecation warning 2016-03-14 19:21:47 +01:00
Emilien Mantel
97aeda5678 New feature: redirect_https (HTTP -> HTTPS) 2016-03-14 19:20:08 +01:00
Emilien Mantel
3666b29184 nghttp2 only on Debian Jessie+ 2016-03-09 15:03:41 +01:00
Emilien Mantel
9b5f136510 Fix trailing whitespaces 2016-03-09 11:20:19 +01:00
Emilien Mantel
7cc44bc009 Fix regression (merge?): filename for vhosts 2016-03-09 11:15:37 +01:00
Emilien Mantel
078c3420e1 Fix Vagrantfile (debian is not freebsd)... uh? :) 2016-03-09 10:28:06 +01:00
Emilien Mantel
2cfda9a930 Fix check HTTP2 on FreeBSD (multi-OS code) 2016-03-08 19:37:39 +01:00
E Mantel
29a40fc0a8 Merge pull request #14 from HanXHX/freebsd
Freebsd support
2016-03-08 18:59:38 +01:00
Emilien Mantel
33f34a0550 Manage FreeBSD nginx package name 2016-03-07 12:08:34 +01:00
Emilien Mantel
8fc6f7117e Doc fixes 2016-03-07 12:05:58 +01:00
Emilien Mantel
972555ce22 Minor fixes 2016-03-07 11:59:26 +01:00
Emilien Mantel
2f0672359d I support now FreeBSD! 2016-03-05 18:43:49 +01:00
Emilien Mantel
cdc152afbe Nagios OK on FreeBSD 2016-03-05 18:34:04 +01:00
Emilien Mantel
729b621ccb Fix check htpasswd in location (replace echo test) 2016-03-05 17:31:21 +01:00
Emilien Mantel
c13cb0d770 PHP works on FreeBSD 2016-03-05 17:26:05 +01:00
Emilien Mantel
8edd69547d [WIP] split pre/post tasks related to OS version 2016-03-05 15:46:54 +01:00
Emilien Mantel
791832f6d1 Config seems ok 2016-03-05 15:36:25 +01:00
Emilien Mantel
e00313bb36 [WIP] FreeBSD install ok 2016-03-05 15:07:39 +01:00
Emilien Mantel
44a5c31b12 Typofix 2016-03-05 12:12:09 +01:00
Emilien Mantel
232e63dffe Add travis webhook to galaxy 2016-03-05 12:06:08 +01:00
Emilien Mantel
fe68e17663 Logging must be set to false to be disabled 2016-03-05 12:00:07 +01:00
Emilien Mantel
ac61b3df0a Add new galaxy tags 2016-03-05 11:40:43 +01:00
Emilien Mantel
1071881ac2 Merge branch 'master' of https://github.com/HanXHX/ansible-nginx
Conflicts:
	tasks/vhost.yml
2016-03-05 11:39:29 +01:00
Emilien Mantel
e139ab3e35 Fix deprecation warnings 2016-03-05 11:37:37 +01:00
Emilien Mantel
1f82e7adfe Add HTTP2 check 2016-03-05 11:30:48 +01:00
Emilien Mantel
e43a958b03 Gitignore *.retry 2016-03-05 11:06:34 +01:00
Emilien Mantel
47c24a2eb3 Fix HTTP2 syntax error 2016-03-05 10:59:20 +01:00
Emilien Mantel
82c44be932 Use official debian box and DHCP 2016-03-05 10:46:46 +01:00
Emilien Mantel
781008dfff Each vhost can have his own filename 2016-03-04 16:38:40 +01:00
Emilien Mantel
26a50945c5 Split apt update cache (fix install when cache is outdated) 2016-02-09 18:36:48 +01:00
Emilien Mantel
4dc28d9471 Delete useless tasks 2016-02-09 17:17:44 +01:00
Emilien Mantel
3231e58bc0 Test stub status on default http vhost 2016-02-09 16:57:13 +01:00
Emilien Mantel
d4f9b6f710 Fix default var nginx_custom_http 2016-01-26 11:19:51 +01:00
Emilien Mantel
d049be0d81 Remove duplicate link 2016-01-25 17:02:17 +01:00
46 changed files with 740 additions and 207 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vagrant*
*.swp
*.retry

View File

@@ -1,5 +1,4 @@
env:
- PLATFORM=debian-wheezy
- PLATFORM=debian-jessie
sudo: required
@@ -11,3 +10,6 @@ services:
script:
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -1,9 +1,9 @@
Nginx for Debian Ansible role
=============================
Nginx for Debian/FreeBSD 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?branch=master)](https://travis-ci.org/HanXHX/ansible-nginx)
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.nginx-blue.svg)](https://galaxy.ansible.com/HanXHX/nginx/) [![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/FreeBSD.
Features:
@@ -24,9 +24,15 @@ Role Variables
### Packaging
Debian:
- `nginx_apt_package`: APT nginx package (try: apt-cache search ^nginx)
- `nginx_backports`: Install nginx from backport repository (bool)
FreeBSD:
- `nginx_pkgng_package`: PKGNG nginx package (should be "nginx" or "nginx-devel")
### Shared
- `nginx_root`: root directory where you want to have your files
@@ -34,6 +40,7 @@ Role Variables
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
- `nginx_error_log_level`: default log level
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
- `nginx_fastcgi_fix_realpath`: boolean, use realpath for fastcgi (fix problems with symlinks and PHP opcache)
### Nginx Configuration
@@ -53,12 +60,19 @@ Fine configuration
[Upstream Configuration](doc/upstream.md)
[Vhost configuration](doc/vhost.md)
[SSL/TLS Configuration](doc/ssl.md)
[Basic Auth](doc/auth.md)
[FreeBSD](doc/freebsd.md)
Note
----
- Active support for Debian.
- FreeBSD support is experimental (no Travis). I only test (for the moment) 10.2 (but it can work on other versions).
- I don't manage BackupPC for FreeBSD (PR welcome).
Dependencies
------------

37
Vagrantfile vendored
View File

@@ -5,10 +5,13 @@
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-stretch", "sharlak/debian_stretch_64", "192.168.33.29" ]
vms_debian = [
[ "debian-jessie", "debian/jessie64" ],
[ "debian-stretch", "sharlak/debian_stretch_64" ]
]
vms_freebsd = [
[ "freebsd-10.2", "freebsd/FreeBSD-10.2-STABLE" ]
]
config.vm.provider "virtualbox" do |v|
@@ -16,11 +19,10 @@ Vagrant.configure("2") do |config|
v.memory = 256
end
vms.each do |vm|
vms_debian.each do |vm|
config.vm.define vm[0] do |m|
m.vm.box = vm[1]
m.vm.network "private_network", ip: vm[2]
m.vm.network "private_network", type: "dhcp"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.groups = { "test" => [ vm[0] ] }
@@ -29,4 +31,25 @@ Vagrant.configure("2") do |config|
end
end
end
# See: https://forums.freebsd.org/threads/52717/
vms_freebsd.each do |vm|
config.vm.define vm[0] do |m|
m.vm.box = vm[1]
m.vm.network "private_network", type: "dhcp"
m.vm.guest = :freebsd
m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
m.ssh.shell = "sh"
m.vm.base_mac = "080027D14C66"
m.vm.provision "shell", inline: "pkg install -y python bash"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.groups = { "test" => [ vm[0] ] }
ansible.verbose = 'vv'
ansible.sudo = true
ansible.extra_vars = {
ansible_python_interpreter: '/usr/local/bin/python'
}
end
end
end
end

View File

@@ -1,14 +1,16 @@
---
# Debian
nginx_apt_package: nginx-full
nginx_backports: false
# FreeBSD
nginx_pkgng_package: nginx
#
# Nginx shared variables
#
nginx_root: "/srv/www"
nginx_log_dir: '/var/log/nginx'
nginx_pid: '/run/nginx.pid'
nginx_resolver_hosts: ['8.8.8.8', '8.8.4.4']
nginx_resolver_valid: '300s'
nginx_resolver_timeout: '5s'
@@ -16,22 +18,26 @@ nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#er
nginx_auto_config_httpv2: true
nginx_default_vhost: null
nginx_default_vhost_ssl: null
nginx_fastcgi_fix_realpath: true
#
# Nginx directories
#
nginx_htpasswd_dir: '/etc/nginx/htpasswd'
nginx_ssl_dir: '/etc/nginx/ssl'
nginx_helper_dir: '/etc/nginx/helper'
nginx_htpasswd_dir: '{{ nginx_etc_dir }}/htpasswd'
nginx_ssl_dir: '{{ nginx_etc_dir }}/ssl'
nginx_helper_dir: '{{ nginx_etc_dir}}/helper'
#
# Load upstream
#
# PHP
nginx_php: false
nginx_php_sockets:
- unix_socket: "/var/run/php5-fpm.sock"
nginx_php56: false
nginx_php70: false
nginx_php56_sockets:
- unix_socket: "/run/php5-fpm.sock"
nginx_php70_sockets:
- unix_socket: "/run/php/php7.0-fpm.sock"
nginx_upstreams: []
#
@@ -45,7 +51,6 @@ nginx_worker_processes: '{{ ansible_processor_vcpus }}'
#
nginx_events_worker_connections: '512'
nginx_events_multi_accept: 'on'
nginx_events_use: 'epoll'
#
# Nginx HTTP
@@ -81,9 +86,9 @@ nginx_http_gzip_vary: 'on'
nginx_http_gzip_disable: '"msie6"'
#
# nginx_http_custom
# Custom global configuration
#
nginx_http_custom: []
nginx_custom_http: []
#
# Vhosts
@@ -106,3 +111,10 @@ nginx_ssl_pairs: []
nginx_dh: null
nginx_dh_path: '{{ nginx_ssl_dir }}/dhparam.pem'
nginx_dh_length: 2048
# Extra
# Note:
# - On Debian, if you use Owncloud from Upstream repository, you must set this var to "/var/www/owncloud"
# - TODO: force this var in vars/FreeBSD.yml
nginx_owncloud_root: '/usr/share/owncloud'

View File

@@ -10,19 +10,19 @@ Each htpasswd has few keys:
- `name`: (M) used to create file and as pointee
- `description`: (M) Used for the message box :)
- `users`: each users is composed with 3 keys: `name` (M), `password` (M) and `state` present/absent (default: present)
- `users`: each users is composed with 3 keys: `name` (M), `password` (M) and `state` (O) present/absent (default: present)
- `state`: (O) present or absent. Default: present
`nginx_htpasswd` should be placed in a vaut file.
`nginx_htpasswd` should be placed in a vault file.
Example
-------
```
```yaml
nginx_vhosts:
# htpasswd on all vhost
- name: test.local
htpasswd: 'hello'
htpasswd: 'hello'
template: '_base'
# htpasswd only in /hello
@@ -30,7 +30,7 @@ nginx_vhosts:
template: '_base'
location:
'/hello':
- htpasswd: 'hello'
- htpasswd: 'hello'
nginx_htpasswd:
- name: 'hello'

4
doc/freebsd.md Normal file
View File

@@ -0,0 +1,4 @@
Freebsd
=======
Due to Ansible + FreeBSD limitations (`ansible_processor_vcpus`), You must explicitely set `nginx_worker_processes`.

View File

@@ -1,8 +1,8 @@
PHP
===
- `nginx_php`: boolean if you need to preconfigure PHP (default: false)
- `nginx_php_sockets`: list of sockets (see bellow)
- `nginx_php56` and `nginx_php70`: boolean if you need to preconfigure PHP (default: false)
- `nginx_php##_sockets`: list of sockets (see bellow)
You should see [Nginx upstream module doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
@@ -15,4 +15,4 @@ Each socket have:
- `max_fails`
- `fail_timeout`
With default configuration, it works fine with PHP-FPM. But if you install PHP7 with Dotdeb, path changed between version, you must set well this list.
With default configuration, it works fine with PHP-FPM.

View File

@@ -17,7 +17,7 @@ Cert/Key pairs
This list have 3 mandatory keys:
- `name`: MUST be unique
- `name`: MUST be unique
- `key`: content of the private key
- `cert`: content of the public key
@@ -27,7 +27,6 @@ OR
- `dest_cert`: remote path where certificate is located
- `dest_key`: remote path where key is located
Note: `name` is used to deploy key/cert. With defaults values dans `name` = "foo", key is -> /etc/nginx/ssl/foo/foo.key
Tips
@@ -35,9 +34,6 @@ Tips
Deploying key/cert is not mandatory with this role. You can manage it in other place ([letsencrypt](https://letsencrypt.org/)? :)). You just need to set `dest_cert` and `dest_key`!
If you set all, you can deploy your key everywhere with wanted data!
Diffie-Hellman
--------------
@@ -46,7 +42,7 @@ If you do not specify any dh param, this role auto generates it.
Example
-------
```
```yaml
nginx_vhosts;
- name: 'test-ssl.local'
proto: ['http', 'https']

View File

@@ -11,6 +11,7 @@ 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
- `state`: Optional. Can be 'absent' or 'present'
Server params
-------------
@@ -25,5 +26,18 @@ All this params are optional. You should see [Nginx upstream doc](http://nginx.o
- `backup`
- `down`
- `route`
- `slow`start`
- `slow_start`
Example
-------
```yaml
nginx_upstreams:
- name: 'proxy_apache'
servers:
- path: '127.0.0.1:80'
max_conns: 150
weight: 10
down: false
state: 'present'
```

View File

@@ -10,11 +10,13 @@ Common
- `name`: (M) Domain or list of domain used.
- `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)
- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword).
- `state`: (O) Vhost status. Can be "present" (default), "absent" and "disabled".
- `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).
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
- `redirect_to_code`: Redirect code (default: 302)
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
- `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)
@@ -23,6 +25,8 @@ Common
- `htpasswd`: (O) References name key in `nginx_htpasswd`. Enable auth basic on all vhost.
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
- `ssl_name`: (D) name of the key used when using TLS/SSL. Mandatory when `proto` contains "https"
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
- `php_version` (O) Sepecify PHP version (5 or 7)
(O): Optional
(M): Mandatory
@@ -36,6 +40,7 @@ Templates
- `_dokuwiki`
- `_redirect`: should not be called explicitly
- `_nagios3`: access to Nagios3 (be careful: you need to install [fcgiwrap](https://packages.debian.org/jessie/fcgiwrap))
- `_owncloud`: access to Owncloud (note: you must set `nginx_apt_package` to //nginx-extras//) **UNSTABLE**
- `_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

View File

@@ -1 +0,0 @@
<h1>HTML works</h1>

View File

@@ -1,3 +0,0 @@
<?php
echo "<h1>PHP works!</h1>";

View File

@@ -1,4 +1,13 @@
---
# Reload wrapper
- name: reload nginx
action: service name=nginx state=reloaded enabled=yes
command: nginx -t
notify: real-reload nginx
- name: real-reload nginx
service: name=nginx state=reloaded
- name: restart nginx freebsd
service: name=nginx state=restarted
when: ansible_distribution == "FreeBSD"

View File

@@ -1,16 +1,26 @@
---
galaxy_info:
author: Emilien Mantel
description: Nginx for Debian
description: Nginx for Debian
company:
license: GPLv2
license: GPLv2
min_ansible_version: 2.0
platforms:
- name: Debian
versions:
- wheezy
- jessie
categories:
- name: FreeBSD
versions:
- 10.2
galaxy_tags:
- web
- proxy
- http
- http2
- https
- ssl
- tls
- nginx
- cdn
dependencies: []

View File

@@ -3,7 +3,7 @@
- name: TEMPLATE | Deploy nginx.conf
template: >
src=etc/nginx/nginx.conf.j2
dest=/etc/nginx/nginx.conf
dest="{{ nginx_etc_dir }}/nginx.conf"
notify: reload nginx
- name: TEMPLATE | Deploy all helpers
@@ -16,6 +16,19 @@
- name: TEMPLATE | Deploy custom http configuration
template: >
src=etc/nginx/conf.d/custom.conf.j2
dest=/etc/nginx/conf.d/custom.conf
dest="{{ nginx_etc_dir }}/conf.d/custom.conf"
notify: reload nginx
- name: LINEINFILE | Fix path
lineinfile: >
regexp='{{ item.0.regexp }}'
line='{{ item.0.line }}'
dest='{{ item.1 }}'
with_nested:
-
- regexp: '^fastcgi_param SCRIPT_FILENAME'
line: 'fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;'
- regexp: '^fastcgi_param DOCUMENT_ROOT'
line: 'fastcgi_param DOCUMENT_ROOT $realpath_root;'
- [ '/etc/nginx/fastcgi_params', '/etc/nginx/fastcgi.conf' ]
when: nginx_fastcgi_fix_realpath

View File

@@ -4,7 +4,7 @@
file: >
path={{ nginx_htpasswd_dir }}/{{ item.name }}
state=absent
with_items: nginx_htpasswd
with_items: "{{ nginx_htpasswd }}"
when: item.state is defined and item.state == 'absent'
- name: HTPASSWD | Manage files
@@ -14,6 +14,6 @@
state={{ item.1.state | default('present') }}
path={{ nginx_htpasswd_dir }}/{{ item.0.name }}
with_subelements:
- nginx_htpasswd
- "{{ nginx_htpasswd }}"
- users
when: item.0.state is not defined or item.0.state == 'present'
when: item.0.state is not defined or item.0.state == 'present'

View File

@@ -1,11 +1,21 @@
---
- name: APT | Update cache
apt: >
update_cache=yes
cache_valid_time=3600
- name: APT | Force OpenSSL from backports (fix dependency break)
apt: >
pkg=openssl
state=latest
default_release={{ ansible_distribution_release + '-backports' }}
when: nginx_backports
- name: APT | Install nginx and dependencies
apt: >
pkg={{ nginx_apt_package }}
state=present
update_cache=yes
cache_valid_time=3600
default_release={{ ansible_distribution_release + '-backports' if nginx_backports else ansible_distribution_release }}
- name: APT | Install python-passlib

46
tasks/install_FreeBSD.yml Normal file
View File

@@ -0,0 +1,46 @@
---
- name: PKGNG | Install nginx and related tools
pkgng: name={{ item }} state=present
with_items:
- "{{ nginx_pkgng_package }}"
- py27-passlib
- curl
- name: FILE | Create configuration dir (like Debian)
file: path="{{ nginx_etc_dir }}/{{ item }}" state=directory
with_items:
- conf.d
- sites-available
- sites-enabled
- name: STAT | Check fastcgi.conf
stat: path={{ nginx_etc_dir }}/fastcgi.conf
register: conf
- name: COPY | config
command: "cp {{ nginx_etc_dir }}/fastcgi_params {{ nginx_etc_dir }}/fastcgi.conf"
when: not conf.stat.exists
notify: reload nginx
- name: LINEINFILE | Add fastcgi config
lineinfile: >
line="fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;"
dest="{{ nginx_etc_dir }}/fastcgi.conf"
notify: reload nginx
- name: COPY | Populate proxy_params
copy: >
content="proxy_set_header Host $http_host;\nproxy_set_header X-Real-IP $remote_addr;\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;"
dest="{{ nginx_etc_dir }}/proxy_params"
- name: FILE | Create log directory
file: >
path={{ nginx_log_dir }}
owner={{ nginx_user }}
group=wheel
mode=0755
state=directory
- name: SERVICE | Enable nginx
service: name=nginx enabled=yes

View File

@@ -1,7 +1,10 @@
---
- name: INCLUDE_VARS | Related to OS
include_vars: "{{ ansible_distribution }}.yml"
- name: INCLUDE | Install
include: install.yml
include: install_{{ ansible_distribution }}.yml
- name: INCLUDE | Prepare
include: prepare.yml

View File

@@ -2,14 +2,22 @@
- name: SHELL | Get Nginx version
shell: nginx -v 2>&1 | sed -r 's#.*/##;' | cut -d ' ' -f 1
args:
executable: /bin/sh
register: nginx_version
changed_when: false
- name: SHELL | Get module list
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed -r 's/_module\s*$//g' |sort
register: nginx_modules
shell: nginx -V 2>&1 | tr -- - '\n' | grep -A 1 with | grep _module | sed 's/_module[[:space:]]*//g' | sort
args:
executable: /bin/sh
register: shell_modules
changed_when: false
- name: SET_FACT | Save modules
set_fact:
nginx_modules: "{{ shell_modules.stdout_lines }}"
- name: FILE | Create folders
file: dest={{ item }} owner=root mode=0755 state=directory
with_items: "{{ nginx_dirs }}"

View File

@@ -18,14 +18,14 @@
file: >
path="{{ nginx_ssl_dir + '/' + item.name }}"
state=directory
with_items: nginx_ssl_pairs
with_items: "{{ nginx_ssl_pairs }}"
when: item.dest_key is not defined or item.dest_cert is not defined
- name: COPY | Deploy SSL keys
copy: >
content="{{ item.key }}"
dest="{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.key' if item.dest_key is not defined else item.dest_key }}"
with_items: nginx_ssl_pairs
with_items: "{{ nginx_ssl_pairs }}"
when: item.key is defined
notify: reload nginx
@@ -33,7 +33,7 @@
copy: >
content="{{ item.cert }}"
dest="{{ nginx_ssl_dir + '/' + item.name + '/' + item.name + '.crt' if item.dest_cert is not defined else item.dest_cert }}"
with_items: nginx_ssl_pairs
with_items: "{{ nginx_ssl_pairs }}"
when: item.cert is defined
notify: reload nginx

View File

@@ -1,11 +1,29 @@
---
- name: SET_FACT | Backward compatibility with old version of this role
set_fact: >
nginx_php56: true
when: nginx_php is defined and nginx_php
- 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
template: >
src=etc/nginx/upstream/php.conf.j2
dest="{{ nginx_etc_dir }}/conf.d/php.conf"
when: nginx_php56 or nginx_php70
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
template: >
src=etc/nginx/upstream/upstream.conf.j2
dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
with_items: "{{ nginx_upstreams }}"
when: item.state is not defined or item.state == 'present'
notify: reload nginx
- name: FILE | Delete other upstreams
file: >
path={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
state=absent
with_items: "{{ nginx_upstreams }}"
when: item.state is defined and item.state == 'absent'
notify: reload nginx

View File

@@ -1,93 +1,85 @@
---
- name: FAIL | Check filenames
fail: msg="Forbidden keyword default on vhost {{ item.name if item.name is string else item.name[0] }}"
when: item.filename is defined and item.filename == 'default'
with_items: "{{ nginx_vhosts }}"
- name: FAIL | Check vhost and SSL/TLS support
fail: msg="Missmatch configuration for vhost {{ item.name if item.name is string else item.name[0] }}"
when: >
item.proto is defined and
'https' in item.proto and
item.ssl_name is not defined
with_items: nginx_vhosts
with_items: "{{ nginx_vhosts }}"
- name: FAIL | Check HTTPS redir and proto
fail: msg="You can't have HTTP proto and HTTPS redirection at the same time"
when: >
((item.proto is defined and 'http' in item.proto) or (item.proto is not defined)) and
(item.redirect_http is defined and item.redirect_http)
with_items: "{{ nginx_vhosts }}"
- name: FILE | Create root directory
file: >
path={{ nginx_root }}
state=directory
- name: FILE | Create root folders (foreach nginx_vhosts)
file: >
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}
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 not in nginx_templates_no_dir) and
(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: >
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') }}
owner={{ item.owner | default(nginx_user) }}
group={{ item.group | default(nginx_user) }}
mode={{ item.mode | default('0755') }}
with_items: nginx_vhosts
with_items: "{{ nginx_vhosts }}"
when: >
item.root is not defined and
(item.template is defined and item.template not in nginx_templates_no_dir) and
(item.delete is not defined or not item.delete) and
(item.state is not defined or not item.state != 'absent') and
item.redirect_to is not defined
- name: TEMPLATE | Create vhosts
template: >
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
when: item.delete is not defined or not item.delete
#- name: COPY | Add index.html / index.php
# copy: src={{ item }} dest={{ nginx_root }}/{{ item.name }}/public/{{ item }} owner=www-data group=www-data mode=0666
# with_fileglob: "web/*"
dest={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
with_items: "{{ nginx_vhosts }}"
notify: ['reload nginx', 'restart nginx freebsd']
when: item.state is not defined or item.state != 'absent'
- name: FILE | Delete vhosts
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
file: path={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
with_items: "{{ nginx_vhosts }}"
notify: ['reload nginx', 'restart nginx freebsd']
when: item.state is defined and item.state == 'absent'
- name: FILE | Enable vhosts
file: >
src=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }}
dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }}
src={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
dest={{ nginx_etc_dir }}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
state=link
with_items: nginx_vhosts
notify: reload nginx
with_items: "{{ nginx_vhosts }}"
notify: ['reload nginx', 'restart nginx freebsd']
when: >
((item.enable is not defined) or
(item.enable is defined and item.enable)) and
(item.delete is not defined or not item.delete)
item.state is not defined or item.state == 'present'
- name: FILE | Disable vhosts
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) or (item.delete is defined and item.delete)
file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
with_items: "{{ nginx_vhosts }}"
notify: ['reload nginx', 'restart nginx freebsd']
when: item.state is defined and item.state == 'disabled'
- name: FILE | Delete default vhost when explicitely defined
file: >
path=/etc/nginx/sites-enabled/default
path={{ nginx_etc_dir }}/sites-enabled/default
state=absent
notify: reload nginx
notify: ['reload nginx', 'restart nginx freebsd']
when: nginx_default_vhost is not none
- name: FILE | Auto set default vhost
file: >
src=/etc/nginx/sites-available/default
dest=/etc/nginx/sites-enabled/default
src={{ nginx_etc_dir }}/sites-available/default
dest={{ nginx_etc_dir }}/sites-enabled/default
state=link
notify: reload nginx
notify: ['reload nginx', 'restart nginx freebsd']
when: nginx_default_vhost is none

View File

@@ -2,13 +2,11 @@
# {{ ansible_managed }}
#
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES128-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA128:DHE-RSA-AES128-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA128:ECDHE-RSA-AES128-SHA384:ECDHE-RSA-AES128-SHA128:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA128:DHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA384:AES128-GCM-SHA128:AES128-SHA128:AES128-SHA128:AES128-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
{% if nginx_version.stdout | version_compare('1.3.7', 'ge') %}
ssl_stapling on;
ssl_stapling_verify on;

View File

@@ -2,13 +2,11 @@
# {{ ansible_managed }}
#
ssl_ciphers "AES256+EECDH:AES256+EDH";
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
{% if nginx_version.stdout | version_compare('1.3.7', 'ge') %}
ssl_stapling on;
ssl_stapling_verify on;

View File

@@ -14,7 +14,7 @@ events {
http {
types_hash_max_size {{ nginx_http_types_hash_max_size }};
include /etc/nginx/mime.types;
include {{ nginx_etc_dir }}/mime.types;
default_type {{ nginx_http_default_type }};
access_log {{ nginx_http_access_log }};
@@ -45,8 +45,8 @@ http {
gzip_vary {{ nginx_http_gzip_vary }};
gzip_disable {{ nginx_http_gzip_disable }};
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
include {{ nginx_etc_dir }}/conf.d/*.conf;
include {{ nginx_etc_dir }}/sites-enabled/*;
}
# vim:filetype=nginx

View File

@@ -25,7 +25,7 @@
{% block template_upstream_location %}
location ~ \.cgi$ {
gzip off;
include /etc/nginx/fastcgi_params;
include {{ nginx_etc_dir }}/fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_index BackupPC_Admin;
fastcgi_param SCRIPT_FILENAME /usr/share/backuppc/cgi-bin$fastcgi_script_name;

View File

@@ -3,6 +3,7 @@
{% set __listen = item.listen | default(['80']) %}
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
{% set __location = item.location | default({}) %}
{% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %}
{% macro htpasswd(htpasswd_name, indent=1) -%}
{% for ht in nginx_htpasswd if ht.name == htpasswd_name %}
{{ "\t" * indent }}auth_basic "{{ ht.description }}";
@@ -30,10 +31,12 @@ server {
{% endif %}
{% if 'https' in __proto %}
{% for port in __listen_ssl %}
listen {{ port }}{% if nginx_default_vhost_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules.stdout_lines %}http2{% endif %};
listen {{ port }}{% if nginx_default_vhost_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %};
{% endfor %}
{{ ssl(item.ssl_name) }}
{% if item.ssl_template is not defined or item.ssl_template != false %}
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
{% endif %}
{% endif %}
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
{% block root %}
@@ -47,16 +50,26 @@ server {
index {{ item.index | default('index.html index.htm') }};
{% endblock %}
{% block template_more %}
{% if item.more is defined and item.more is iterable %}
{% for line in item.more %}
{{ line }}
{% endfor %}
{% endif %}
{% endblock %}
{% if item.htpasswd is defined %}
{{ htpasswd(item.htpasswd, 1) }}
{% endif %}
{% block template_headers %}
# --> Custom headers
{% for key, value in __headers.iteritems() %}
add_header {{ key }} {{ value | replace(' always', '') }}{% if nginx_version.stdout | version_compare('1.7.5', 'ge') and ' always' in value %} always{% endif %};
{% endfor %}
# <-- Custom headers
{% endblock %}
{% if not __location.has_key('/') %}
location / {
{% block template_try_files %}
@@ -70,6 +83,19 @@ server {
{% block template_custom_location %}
{% endblock %}
{% if __location is iterable and __location | length > 0 %}
# --> Custom locations
{% for location, opts in __location.iteritems() %}
location {{ location }} {
{% for opt in opts %}
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
{{ opt }}
{% endif %}
{% endfor %}
}
{% endfor %} # <-- Custom locations
{% endif %}
{% block template_local_content %}
{% if item.manage_local_content is not defined or item.manage_local_content %}
location ~ /\.ht {
@@ -89,31 +115,36 @@ server {
{% endif %}
{% endblock %}
{% if __location is iterable and __location | length > 0 %}
# --> Custom locations
{% for location, opts in __location.iteritems() %}
location {{ location }} {
{% for opt in opts %}
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
{{ opt }}
{% endif %}
{% endfor %}
}
{% endfor %} # <-- Custom locations
{% endif %}
{% if item.use_access_log is defined and item.use_access_log %}
{% if item.use_access_log is defined %}
{% if item.use_access_log %}
access_log {{ nginx_log_dir }}/{{ __main_name }}_access.log combined;
{% else %}
access_log off;
{% endif %}
{% if item.use_error_log is defined and item.use_error_log %}
{% endif %}
{% if item.use_error_log is defined %}
{% if item.use_error_log %}
error_log {{ nginx_log_dir }}/{{ __main_name }}_error.log {{ nginx_error_log_level }};
{% else %}
error_log off;
{% endif %}
{% endif %}
}
{% if item.redirect_https is defined and item.redirect_https %}
#
# Redirect HTTP to HTTPS
#
server {
{% for port in __listen %}
listen {{ port }};
{% endfor %}
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl %}:__listen_ssl[0]{% endif %}$request_uri;
}
{% endif %}
{% if item.redirect_from is defined and item.redirect_from is iterable %}
#
# Redirect from

View File

@@ -1,7 +1,7 @@
{% extends "_base.j2" %}
{% extends "_php.j2" %}
{% block root %}
root /usr/share/nagios3/htdocs;
root {{ nginx_nagios_root }};
{% endblock %}
{% block template_try_files %}
@@ -11,32 +11,52 @@
index index.php index.html;
{% endblock %}
{% block template_headers %}
# --> Custom headers
{% for key, value in __headers.iteritems() %}
{% if key == "X-Frame-Options" %}
# X-Frame-Options forced by Ansible
add_header {{ key }} SAMEORIGIN{% if nginx_version.stdout | version_compare('1.7.5', 'ge') %} always{% endif %};
{% else %}
add_header {{ key }} {{ value | replace(' always', '') }}{% if nginx_version.stdout | version_compare('1.7.5', 'ge') and ' always' in value %} always{% endif %};
{% endif %}
{% endfor %}
# <-- Custom headers
{% endblock %}
{% block template_local_content %}
location ~ /\.ht {
deny all;
}
location /stylesheets {
alias /etc/nagios3/stylesheets;
{% if nginx_nagios_stylesheets is defined %}
alias {{ nginx_nagios_stylesheets }};
{% endif %}
expires 60d;
}
{% endblock %}
{% block template_upstream_location %}
{% if ansible_distribution == 'Debian' %}
location /cgi-bin/nagios3 {
root /usr/lib;
{% elif ansible_distribution == 'FreeBSD' %}
location /cgi-bin {
{% endif %}
try_files $uri =404;
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
include fastcgi_params;
{% else %}
include fastcgi.conf;
{% endif %}
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_pass unix:{{ nginx_fcgiwrap_sock }};
fastcgi_param AUTH_USER $remote_user;
fastcgi_param REMOTE_USER $remote_user;
}
location ~ \.php$ {
fastcgi_pass php;
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
include fastcgi_params;

View File

@@ -0,0 +1,87 @@
{% extends "_php.j2" %}
{% block root %}
root {{ nginx_owncloud_root }};
{% endblock %}
{% block template_index %}
index index.php;
{% endblock %}
{% block template_more %}
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
gzip off;
client_max_body_size 10G;
fastcgi_buffers 64 4K;
rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
{% endblock %}
{% block template_headers %}
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Content-Type-Options nosniff;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options SAMEORIGIN;
{% endblock %}
{% block template_try_files %}
try_files $uri $uri/ =404;
{% endblock %}
{% block template_upstream_location %}
location ~ /remote.php {
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
fastcgi_pass {{ php_upstream }};
fastcgi_param HOME {{ nginx_owncloud_root }};
fastcgi_param HTTP_HOME {{ nginx_owncloud_root }};
fastcgi_param PATH /usr/local/bin:/usr/bin:/bin;
fastcgi_param modHeadersAvailable true;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
include fastcgi_params;
{% else %}
include fastcgi.conf;
{% endif %}
}
location ~ \.php(?:$|/) {
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
fastcgi_param HOME {{ nginx_owncloud_root }};
fastcgi_param HTTP_HOME {{ nginx_owncloud_root }};
fastcgi_param PATH /usr/local/bin:/usr/bin:/bin;
fastcgi_param modHeadersAvailable true;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
include fastcgi_params;
{% else %}
include fastcgi.conf;
{% endif %}
}
{% endblock %}
{% block template_local_content %}
location ~* \.(?:css|js)$ {
try_files $uri /index.php$is_args$args;
expires 2h;
}
location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
expires 2d;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(?:\.ht|data|config|db_structure\.xml|README){
deny all;
}
{% endblock %}

View File

@@ -1,4 +1,24 @@
{% extends "_base.j2" %}
{% macro phpv(version) %}
{% if version == 56 or version == "5.6" %}
{{ nginx_upstream_php56 -}}
{% elif version == 70 or version == "7.0" %}
{{ nginx_upstream_php70 -}}
{% else %}
{# Hack... define another upstream #}
{{ version -}}
{% endif %}
{%- endmacro -%}
{% if item.php_version is defined %}
{% set php_upstream = phpv(item.php_version) %}
{% elif nginx_php56 %}
{% set php_upstream = phpv(56) %}
{% elif nginx_php70 %}
{% set php_upstream = phpv(70) %}
{% endif %}
{% block template_index %}
index {{ item.index | default('index.html index.htm index.php') }};
{% endblock %}
@@ -9,7 +29,7 @@
{% block template_upstream_location %}
location ~ \.php$ {
fastcgi_pass php;
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %}

View File

@@ -2,7 +2,7 @@
{% block template_upstream_location %}
location = /index.php {
fastcgi_pass php;
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %}

View File

@@ -7,7 +7,7 @@
{% endblock %}
{% block template_try_files %}
include /etc/nginx/proxy_params;
include {{ nginx_etc_dir }}/proxy_params;
proxy_pass http://{{ item.upstream_name }};
{% if item.proxy_params is defined and item.proxy_params is iterable %}
{% for param in item.proxy_params %}

View File

@@ -2,8 +2,9 @@
# {{ ansible_managed }}
#
upstream php {
{% for item in nginx_php_sockets %}
{% if nginx_php56 %}
upstream {{ nginx_upstream_php56 }} {
{% for item in nginx_php56_sockets %}
{% if item.unix_socket is defined %}
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
{% else %}
@@ -12,4 +13,18 @@ upstream php {
{% endfor %}
}
{% endif %}
{% if nginx_php70 %}
upstream {{ nginx_upstream_php70 }} {
{% for item in nginx_php70_sockets %}
{% if item.unix_socket is defined %}
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
{% else %}
server {{ item.host }}:{{ item.port }} weight={{ item.weight | default('1') }} max_fails={{ item.max_fails | default('5') }} fail_timeout={{ item.fail_timeout | default('10s') }};
{% endif %}
{% endfor %}
}
{% endif %}
# vim:filetype=nginx

View File

@@ -1,4 +0,0 @@
FROM williamyeh/ansible:debian7-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh"]

View File

@@ -0,0 +1,11 @@
---
- name: APT | Install web apps
apt: pkg={{ item }} state=present install_recommends=no
with_items:
- backuppc
- nagios3
# - owncloud
- name: SERVICE | Ensure backuppc is started
service: name=backuppc state=started

View File

@@ -0,0 +1,31 @@
---
- name: APT | Install web apps
pkgng: pkg={{ item }} state=present
with_items:
- nagios
- backuppc
- name: COMMAND | Activate backuppc config
command: >
cp /usr/local/etc/backuppc/config.pl.sample /usr/local/etc/backuppc/config.pl
creates=/usr/local/etc/backuppc/config.pl
- name: FILE | Fix backuppc permissions
file: >
path=/usr/local/etc/backuppc/config.pl
owner=backuppc
group=backuppc
- name: FILE | Fix fcgiwrap permission
file: >
path={{ nginx_fcgiwrap_sock }}
mode=0640
owner={{ nginx_user }}
group={{ nginx_user }}
#
# We don't manage BackupPC on FreeBSD... too dirty. :/
#
#- name: SERVICE | Ensure backuppc is started
# service: name=backuppc state=started enabled=yes

View File

@@ -0,0 +1,36 @@
---
- name: APT_REPOSITORY | Install backports
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present
- block:
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
- name: APT_REPOSITORY | Install dotdeb (PHP 7)
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present
- name: LINEFILEFILE | Dotdeb priority (prevent install nginx from dotdeb)
copy: >
content="Package: *\nPin: release o=packages.dotdeb.org\nPin-Priority: 100"
dest=/etc/apt/preferences
when: ansible_distribution_release == 'jessie'
- name: APT | Install needed packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items:
- curl
- fcgiwrap
- nghttp2
- php5-fpm
- php5-sqlite
- php7.0-fpm
- php7.0-sqlite3
- strace
- vim
- name: SERVICE | Force start services
service: name={{ item }} state=started
register: sf
with_items:
- php5-fpm
- php7.0-fpm
- fcgiwrap

View File

@@ -0,0 +1,25 @@
---
- name: SET_FACT | FreeBSD web user
set_fact:
nginx_pkgng_package: 'nginx-devel'
nginx_user: 'www'
nginx_php70: false
nginx_php56_sockets:
- host: '127.0.0.1'
port: 9000
- name: PKGNG | Install needed packages
pkgng: pkg={{ item }} state=present
with_items:
- php56
- curl
- fcgiwrap
- nghttp2
- name: SERVICE | Force start services
service: name={{ item }} state=started enabled=yes
register: sf
with_items:
- php-fpm
- fcgiwrap

View File

@@ -1 +0,0 @@
localhost

View File

@@ -3,19 +3,18 @@
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
DIR=$( dirname $0 )
INVENTORY_FILE="$DIR/inventory"
PLAYBOOK="$DIR/test.yml"
set -ev
# Check syntax
ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
# Check role
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK
# Check indempotence
ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK \
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)

View File

@@ -2,23 +2,8 @@
- hosts: all
pre_tasks:
- name: APT_REPOSITORY | Install backports
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present
- name: APT | Install needed packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items:
- php5-fpm
- curl
- fcgiwrap
- name: SERVICE | Force start services
service: name={{ item }} state=started
register: sf
with_items:
- php5-fpm
- fcgiwrap
- name: PAUSE | Prevent bugs (CGI not fully loaded)
pause: seconds=5
when: sf.changed
- name: INCLUDE | Pre_tasks related to OS version
include: "includes/pre_{{ ansible_distribution }}.yml"
- name: FILE | Create an internal SSL dir
file: path={{ int_ansible_ssl_dir }} state=directory
- name: COPY | Deploy test certificate
@@ -29,8 +14,11 @@
# Internal vars
int_ansible_ssl_dir: '/etc/ansible-ssl'
# Role vars
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
nginx_apt_package: 'nginx-extras'
nginx_backports: true
nginx_php: true
nginx_php56: true
nginx_php70: true
nginx_upstreams:
- name: 'test'
servers:
@@ -38,6 +26,13 @@
max_conns: 150
weight: 10
down: false
- name: 'test-absent'
servers:
- path: '127.0.0.1:80'
max_conns: 150
weight: 10
down: false
state: 'absent'
nginx_htpasswd:
- name: 'hello'
description: 'Please login!'
@@ -119,23 +114,30 @@
- 'test-alias.local'
- 'test2-alias.local'
template: '_base'
filename : 'first-test'
override_try_files: '$uri $uri index.htm index.html'
headers:
'X-Frame-Options': 'deny always'
'X-ansible-default': '1'
manage_local_content: false
use_error_log: false
more:
- 'autoindex off;'
- 'add_header X-ansible-default 1;'
location:
'/test':
- 'return 403;'
'/gunther':
- 'return 404;'
'/status':
- 'stub_status on;'
- 'access_log off;'
- 'allow 127.0.0.1;'
- 'deny all;'
- name: 'test-htpasswd.local'
template: '_base'
location:
'/hello':
- htpasswd: 'hello'
- 'default_type "text/html; charset=UTF-8";'
- 'echo hello;'
- name: 'test-htpasswd-all.local'
template: '_base'
htpasswd: 'hello'
@@ -145,11 +147,14 @@
'/':
- 'alias /var/tmp;'
- name: 'test-php.local'
php_version: 70
upstream_params:
- 'fastcgi_param FOO bar;'
redirect_from:
- 'www.test-php.local'
template: '_php'
use_error_log: true
use_access_log: true
- name: 'test-php-index.local'
template: '_php_index'
- name: 'test-proxy.local'
@@ -157,10 +162,10 @@
- 8080
template: '_proxy'
upstream_name: 'test'
more:
- 'add_header X-proxyfied 1;'
headers:
'X-proxyfied': '1'
- name: 'deleted.local'
delete: true
state: 'absent'
- name: 'redirect-to.local'
redirect_to: 'http://test.local'
- name: 'backuppc.local'
@@ -177,8 +182,16 @@
proto: ['http', 'https']
template: '_base'
ssl_name: 'test-ssl-predeployed.local'
more:
- 'add_header X-ansible-default 1;'
headers:
'X-ansible-default': '1'
ssl_template: false
- name: 'test-ssl-redirect.local'
proto: ['https']
template: '_base'
ssl_name: 'test-ssl.local'
redirect_https: true
# - name: 'owncloud.local'
# template: '_owncloud'
nginx_dh_length: 1024
roles:
- ../../
@@ -186,14 +199,8 @@
# --------------------------------
# Apps
# --------------------------------
- name: APT | Install web apps
apt: pkg={{ item }} state=present
with_items:
- nagios3
- backuppc
- name: SERVICE | Ensure backuppc is started
service: name=backuppc state=started
- name: INCLUDE | Post_tasks related to OS version
include: "includes/post_{{ ansible_distribution }}.yml"
# --------------------------------
# Deploy index files
# --------------------------------
@@ -203,14 +210,17 @@
- name: -- Add HTML file --
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
with_items: ['{{ nginx_root }}/test.local/public', '/var/tmp', '{{ nginx_root }}/test-htpasswd-all.local/public', '{{ nginx_root }}/test-ssl.local/public', '{{ nginx_root }}/test-ssl-predeployed.local/public']
- name: -- Create directory --
file: path={{ nginx_root }}/test-htpasswd.local/public/hello state=directory
- name: -- Add HTML file hello --
copy: dest="{{ nginx_root }}/test-htpasswd.local/public/hello/index.html" content="hello\n"
# --------------------------------
# Simple vhosts tests
# --------------------------------
- name: -- VERIFY VHOSTS --
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
when: item.delete is undefined or not item.delete
with_items: "{{ nginx_vhosts }}"
when: item.state is undefined or item.state != "absent"
changed_when: false
- name: -- VERIFY FORBIDDEN --
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
@@ -219,8 +229,8 @@
changed_when: false
- name: -- VERIFY REDIRECT VHOSTS --
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
with_items: nginx_vhosts
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
with_items: "{{ nginx_vhosts }}"
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent")
changed_when: false
register: r
failed_when: r.stdout.find('301 Moved Permanently') == -1
@@ -235,21 +245,35 @@
failed_when: p.stdout.find('PHP Version') == -1
with_items: ['test-php.local', 'test-php-index.local']
- name: -- VERIFY PHP5 VHOSTS (implicit default) --
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
register: p
changed_when: false
failed_when: p.stdout.find('PHP Version 5') == -1
with_items: ['test-php-index.local']
- name: -- VERIFY PHP7 VHOSTS --
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
register: p
changed_when: false
failed_when: p.stdout.find('PHP Version 7') == -1
with_items: ['test-php.local']
# --------------------------------
# Basic Auth
# --------------------------------
- name: -- VERIFY AUTH BASIC NONE --
command: "curl -H 'Host: test-htpasswd.local' http://127.0.0.1/hello"
command: "curl -H 'Host: test-htpasswd.local' http://127.0.0.1/hello/"
changed_when: false
register: authnone
failed_when: authnone.stdout.find('401 Authorization Required') == -1
- name: -- VERIFY AUTH BASIC FAIL --
command: "curl -u fail:fail -H 'Host: test-htpasswd.local' http://127.0.0.1/hello"
command: "curl -u fail:fail -H 'Host: test-htpasswd.local' http://127.0.0.1/hello/"
changed_when: false
register: authfail
failed_when: authfail.stdout.find('401 Authorization Required') == -1
- name: -- VERIFY AUTH BASIC OK --
command: "curl -u hanx:qwerty -H 'Host: test-htpasswd.local' http://127.0.0.1/hello"
command: "curl -u hanx:qwerty -H 'Host: test-htpasswd.local' http://127.0.0.1/hello/"
changed_when: false
register: authok
failed_when: authok.stdout.find('hello') == -1
@@ -272,6 +296,7 @@
changed_when: false
register: authbpc
failed_when: authbpc.stdout.find('BackupPC Server Status') == -1
when: ansible_distribution != 'FreeBSD'
# --------------------------------
# Nagios
@@ -282,11 +307,32 @@
register: nagios_php
failed_when: nagios_php.stdout.find('Nagios Core') == -1
- name: -- VERIFY NAGIOS3 CGI --
command: "curl -u nagiosadmin:nagios -H 'Host: nagios3.local' http://127.0.0.1/cgi-bin/nagios3/summary.cgi"
command: "curl -u nagiosadmin:nagios -H 'Host: nagios3.local' http://127.0.0.1/cgi-bin{% if ansible_distribution == 'Debian' %}/nagios3{% endif %}/summary.cgi"
changed_when: false
register: nagios_cgi
failed_when: nagios_cgi.stdout.find('Nagios Event Summary') == -1
# --------------------------------
# Owncloud
# --------------------------------
# - block:
# - name: -- VERIFY OWNCLOUD --
# command: "curl -H 'Host: owncloud.local' http://127.0.0.1/"
# changed_when: false
# register: ownsimple
# failed_when: ownsimple.stdout.find('ownCloud') == -1
# - name: -- VERIFY OWNCLOUD JS (FROM PHP)--
# command: "curl -H 'Host: owncloud.local' http://127.0.0.1/index.php/core/js/oc.js"
# changed_when: false
# register: ownjsphp
# failed_when: ownjsphp.stdout.find('var oc_debug=false') == -1
# - name: -- VERIFY OWNCLOUD JS --
# command: "curl -H 'Host: owncloud.local' http://127.0.0.1/core/js/js.js"
# changed_when: false
# register: ownjs
# failed_when: ownjs.stdout.find('var oc_debug') == -1
# when: ansible_distribution != 'FreeBSD'
# --------------------------------
# SSL
# --------------------------------
@@ -298,6 +344,15 @@
with_items:
- 'test-ssl-predeployed.local'
- 'test-ssl.local'
- name: -- VERIFY SSL REDIRECT --
command: "curl -v --insecure -H 'Host: {{ item }}' http://127.0.0.1/"
changed_when: false
register: sslredirok
failed_when: >
sslredirok.stderr.find('< Location') == -1 and
sslredirok.stderr.find('https://{{ item }}/') == -1
with_items:
- 'test-ssl-redirect.local'
# --------------------------------
# Default vhosts
@@ -326,3 +381,20 @@
changed_when: false
register: notdefaultssl
failed_when: notdefaultssl.stderr.find('X-ansible-default') != -1
- name: -- VERIFY DEFAULT VHOST + STUB_STATUS --
command: "curl -v http://127.0.0.1/status"
changed_when: false
register: vdefault_status
failed_when: >
vdefault_status.stderr.find('X-ansible-default') == -1 or
vdefault_status.stdout.find('Active connections') == -1
# --------------------------------
# Check HTTP2
# --------------------------------
- name: SHELL | Check HTTP2
shell: nghttp -nv https://localhost 2> /dev/null | grep -q h2
args:
executable: /bin/sh
changed_when: false
when: nginx_auto_config_httpv2 and 'http_v2' in nginx_modules

8
vars/Debian.yml Normal file
View File

@@ -0,0 +1,8 @@
nginx_events_use: 'epoll'
nginx_pid: '/run/nginx.pid'
nginx_etc_dir: '/etc/nginx'
# Specific vhosts
nginx_nagios_root: '/usr/share/nagios3/htdocs'
nginx_nagios_stylesheets: '/etc/nagios3/stylesheets'
nginx_fcgiwrap_sock: '/var/run/fcgiwrap.socket'

7
vars/FreeBSD.yml Normal file
View File

@@ -0,0 +1,7 @@
nginx_events_use: 'kqueue'
nginx_pid: '/var/run/nginx.pid'
nginx_etc_dir: '/usr/local/etc/nginx'
# Specific vhosts
nginx_nagios_root: '/usr/local/www/nagios'
nginx_fcgiwrap_sock: '/var/run/fcgiwrap/fcgiwrap.sock'

View File

@@ -28,6 +28,10 @@ nginx_dirs:
- "{{ nginx_helper_dir }}"
nginx_templates_no_dir:
- '_proxy'
- '_nagios3'
- '_backuppc'
- '_nagios3'
- '_owncloud'
- '_proxy'
nginx_upstream_php56: 'php56'
nginx_upstream_php70: 'php70'