Skip to content

Commit 4b52c67

Browse files
author
Pierre Buyle
committed
First commit
0 parents  commit 4b52c67

File tree

15 files changed

+1415
-0
lines changed

15 files changed

+1415
-0
lines changed

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Nginx Drupal
2+
============
3+
4+
Ansible role to configure Nginx for running Drupal using [perusio's configuration](https://github.com/perusio/drupal-with-nginx).
5+
6+
This role only configure Nginx to run Drupal sites, it will not install PHP,
7+
Nginx, Drupal, MySQL, etc. It will however, override the entire content of the
8+
Nginx configuration directory. You can still add file to the Nginx configuration
9+
directory after this role.
10+
11+
Requirements
12+
------------
13+
14+
- Git
15+
- A `reload nginx` handler is used to reload Nginx after configuration changes
16+
and must be defined in your playbook.
17+
18+
Role Variables
19+
--------------
20+
21+
The following variables are available to configure the role:
22+
23+
- **nginx_drupal_git**
24+
- **repo**: The URL of the Git repository to checkout the base
25+
configuration from, defaults to https://github.com/perusio/drupal-with-nginx.git
26+
- **version** The version of the version of the repository to
27+
check out. This can be the full 40-character SHA-1 hash, the literal string
28+
HEAD, a branch name, or a tag name. Defaults to 'D7'.
29+
- **nginx_drupal_config_path**: The path to Nginx configuration folder,
30+
defaults to "/etc/nginx".
31+
- **nginx_drupal_log_path**: The path to Nginx log files, defaults to
32+
"/var/log/nginx"
33+
- **nginx_drupal_php_handling**: The PHP handling method, one of "php-fpm",
34+
"php-cgi" or "proxy", defaults to "php-fpm".
35+
- **nginx_drupal_escape_uri**: Whether or not to escaped URIs, defaults to
36+
false. **No implemented**
37+
- **nginx_drupal_use_boost**: Whether or not [Boost](http://drupal.org/project/boost)
38+
is used, defaults to false. **No implemented**
39+
- **nginx_drupal_use_drush**: Whether or not [Drush](https://github.com/drush-ops/drush)
40+
is used, defaults to true.
41+
- **nginx_drupal_allow_install**: Whether or not to allow access to the
42+
```install.php``` file, defaults to false.
43+
- **nginx_drupal_use_spdy**: Whether or not to use SPDY, defaults to false.
44+
- **nginx_drupal_nginx_status_allowed_hosts**: The list of host allowed to
45+
access Nginx status page, defaults to ```["127.0.0.1", "192.168.1.0/24"]```.
46+
- **nginx_drupal_php_fpm_status_allowed_hosts**: The list of host allowed to
47+
access PHP-FPM status page, defaults to ```["127.0.0.1", "192.168.1.0/24"]```.
48+
- **nginx_drupal_hotlinking_protection**: Whether or not to prevent image
49+
hotlinking, defaults to false.
50+
- **nginx_drupal_admin_basic_auth**: Whether or not to protect access to admin
51+
pages (```/admin/*```) using HTTP auth, defaults to false.
52+
- **nginx_drupal_microcache**: Whether or not to use microcaching, defaults to
53+
true.
54+
- **nginx_drupal_microcache_auth**: Whether or not to use microcaching for
55+
authenticated users, defaults to false.
56+
- **nginx_drupal_upload_progress**: Whether or not to use upload progress (this
57+
require the
58+
- **nginx_drupal_use_aio**: Whether or not to use AIO to server video and audio
59+
file, defaults to true.
60+
- **nginx_drupal_flv_streaming**: Whether or not to use FLV pseudo streaming
61+
(cf. http://wiki.nginx.org/HttpFlvStreamModule), defaults to false.
62+
- **nginx_drupal_mp4_streaming**: Whether or not to use MP4 streaming, (cf.
63+
http://nginx.org/en/docs/http/ngx_http_mp4_module.html) defaults to false.
64+
- **nginx_drupal_upstream_servers**: The list of PHP upstream servers, each item
65+
is a server address (and parameters, see
66+
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server), defaults
67+
to ```["unix:/var/run/php-fpm.sock", "php-fpm-zwei.sock"]```.
68+
- **nginx_drupal_upstream_backup_servers**: The list of PHP upstream backup
69+
servers, defaults to ```["unix:/var/run/php-fpm-bkp.sock"]```.
70+
- **nginx_drupal_sites**: The list of available sites.
71+
Each site uses the following structure:
72+
- **file_name**: The name of the site configuration file.
73+
- **http**: HTTP server configuration (leave empty to disable HTTP)
74+
- **port**: The port to listen on
75+
- **https**: HTTPS server configuration (leave empty to disable HTTPS)
76+
- **port**: The port to listen on
77+
- **certificate**: Path to the SSL certificate of the server (in the PEM
78+
format).
79+
- **certificate_key**: Path to the SSL secret key of the server (in the
80+
PEM format).
81+
- **server_name**: The (primary) server name.
82+
- **ipv6**: (optional) IPv6 address of the server
83+
- **alternate_server_name**: (optional) Alternate server name, configured as
84+
redirect to the primary server site. This can be used to remove the
85+
```www.``` prefix.
86+
- **root**: Path to the root directory for the site.
87+
- **limit_conn**: (optional) The limit_conn for the site (defaults to
88+
```arbeit 32```).
89+
- **enabled**: Whether or not the site should be enabled (defaults to true).
90+
91+
92+
Examples
93+
--------
94+
95+
Two Drupal 7 sites, one available in HTTP and HTTPS. The other only available in
96+
HTTPS but disabled.
97+
98+
99+
- hosts: all
100+
roles:
101+
- role: nginx-drupal
102+
nginx_drupal_sites:
103+
- file_name: foo
104+
server_name: foo.org
105+
alternate_server_name: www.foo.org
106+
root: /var/www/foo
107+
http:
108+
port: 80
109+
https:
110+
port: 443
111+
certificate: /etc/nginx/ssl/foo.cert
112+
certificate_key: /etc/nginx/ssl/foo.key
113+
- file_name: bar
114+
server_name: bar.org
115+
alternate_server_name: www.bar.org
116+
root: /var/www/bar
117+
enabled: false
118+
https:
119+
port: 443
120+
certificate: /etc/nginx/ssl/bar.cert
121+
certificate_key: /etc/nginx/ssl/bar.key
122+
123+
Nginx as a Reverse Proxy for a single Drupal 6 sites, without microcaching and
124+
with image hot linking protection.
125+
126+
127+
- hosts: all
128+
roles:
129+
- role: nginx-drupal
130+
nginx_drupal_git:
131+
version: D6
132+
nginx_drupal_hotlinking_protection: true
133+
nginx_drupal_php_handling: proxy
134+
nginx_drupal_microcache: false
135+
nginx_drupal_sites:
136+
- file_name: foo
137+
server_name: foo.org
138+
alternate_server_name: www.foo.org
139+
root: /var/www/foo
140+
http:
141+
port: 80
142+
143+
License
144+
-------
145+
146+
GPLv3
147+
148+
Author Information
149+
------------------
150+
151+
Pierre Buyle <buyle@pheromone.ca>

defaults/main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
# defaults file for nginx-drupal
3+
nginx_drupal_git:
4+
repo: "https://github.com/perusio/drupal-with-nginx.git"
5+
version: "D7"
6+
7+
nginx_drupal_config_path: "/etc/nginx"
8+
nginx_drupal_log_path: "/var/log/nginx"
9+
nginx_drupal_php_handling: "php-fpm"
10+
nginx_drupal_escape_uri: false
11+
nginx_drupal_use_boost: false
12+
nginx_drupal_use_drush: true
13+
nginx_drupal_allow_install: false
14+
nginx_drupal_use_spdy: false
15+
nginx_drupal_php_fpm_status_allowed_hosts: ["127.0.0.1", "192.168.1.0/24"]
16+
nginx_drupal_nginx_status_allowed_hosts: ["127.0.0.1", "192.168.1.0/24"]
17+
nginx_drupal_hotlinking_protection: false
18+
nginx_drupal_admin_basic_auth: false
19+
nginx_drupal_microcache: true
20+
nginx_drupal_microcache_auth: false
21+
nginx_drupal_upload_progress: true
22+
nginx_drupal_aio: true
23+
nginx_drupal_flv_streaming: true
24+
nginx_drupal_mp4_streaming: true
25+
nginx_drupal_upstream_servers: ["unix:/var/run/php-fpm.sock", "php-fpm-zwei.sock"]
26+
nginx_drupal_upstream_backup_servers: ["unix:/var/run/php-fpm-bkp.sock"]
27+
nginx_drupal_sites: none

handlers/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for nginx-drupal

meta/main.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
galaxy_info:
3+
author: Pierre Buyle
4+
description: Ansible role to configure Nginx for running Drupal
5+
company: Phéromone
6+
license: GPLv3
7+
min_ansible_version: 1.2
8+
#
9+
# Below are all platforms currently available. Just uncomment
10+
# the ones that apply to your role. If you don't see your
11+
# platform on this list, let us know and we'll get it added!
12+
#
13+
#platforms:
14+
#- name: EL
15+
# versions:
16+
# - all
17+
# - 5
18+
# - 6
19+
#- name: GenericUNIX
20+
# versions:
21+
# - all
22+
# - any
23+
#- name: Fedora
24+
# versions:
25+
# - all
26+
# - 16
27+
# - 17
28+
# - 18
29+
# - 19
30+
# - 20
31+
#- name: opensuse
32+
# versions:
33+
# - all
34+
# - 12.1
35+
# - 12.2
36+
# - 12.3
37+
# - 13.1
38+
# - 13.2
39+
#- name: Amazon
40+
# versions:
41+
# - all
42+
# - 2013.03
43+
# - 2013.09
44+
#- name: GenericBSD
45+
# versions:
46+
# - all
47+
# - any
48+
#- name: FreeBSD
49+
# versions:
50+
# - all
51+
# - 8.0
52+
# - 8.1
53+
# - 8.2
54+
# - 8.3
55+
# - 8.4
56+
# - 9.0
57+
# - 9.1
58+
# - 9.1
59+
# - 9.2
60+
#- name: Ubuntu
61+
# versions:
62+
# - all
63+
# - lucid
64+
# - maverick
65+
# - natty
66+
# - oneiric
67+
# - precise
68+
# - quantal
69+
# - raring
70+
# - saucy
71+
# - trusty
72+
#- name: SLES
73+
# versions:
74+
# - all
75+
# - 10SP3
76+
# - 10SP4
77+
# - 11
78+
# - 11SP1
79+
# - 11SP2
80+
# - 11SP3
81+
#- name: GenericLinux
82+
# versions:
83+
# - all
84+
# - any
85+
#- name: Debian
86+
# versions:
87+
# - all
88+
# - etch
89+
# - lenny
90+
# - squeeze
91+
# - wheezy
92+
#
93+
# Below are all categories currently available. Just as with
94+
# the platforms above, uncomment those that apply to your role.
95+
#
96+
#categories:
97+
#- cloud
98+
#- cloud:ec2
99+
#- cloud:gce
100+
#- cloud:rax
101+
#- database
102+
#- database:nosql
103+
#- database:sql
104+
#- development
105+
#- monitoring
106+
#- networking
107+
#- packaging
108+
#- system
109+
#- web
110+
dependencies: []
111+
# List your role dependencies here, one per line. Only
112+
# dependencies available via galaxy should be listed here.
113+
# Be sure to remove the '[]' above if you add dependencies
114+
# to this list.
115+

tasks/git-checkout.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: "Remove existing configurarion directory"
3+
file: path={{nginx_drupal_config_path}} state=absent
4+
- name: "Checkout configuration directory"
5+
git: dest={{nginx_drupal_config_path}} repo={{nginx_drupal_git.repo}} version={{nginx_drupal_git.version}}
6+
notify:
7+
- reload nginx
8+
- name: "Remove example.com configurarion file"
9+
file: path={{nginx_drupal_config_path}}/sites-available/example.com.conf state=absent

tasks/main.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
# tasks file for nginx-drupal
3+
- name: "Get configuration directory's .git stats"
4+
stat: path={{nginx_drupal_config_path}}/.git
5+
register: nginx_drupal_config_path_dot_git
6+
- include: git-checkout.yml
7+
when: nginx_drupal_config_path_dot_git.stat.exists == false
8+
- name: "Create microcache directory"
9+
file: path=/var/cache/nginx/microcache state=directory
10+
when: nginx_drupal_microcache
11+
- name: "Override parametrized configuration files"
12+
template: src={{item}}.j2 dest={{nginx_drupal_config_path}}/{{item}}.conf
13+
with_items:
14+
- apps/drupal/drupal
15+
- php_fpm_status_allowed_hosts
16+
- nginx_status_allowed_hosts
17+
- nginx
18+
- upstream_php
19+
notify:
20+
- reload nginx
21+
- include: sites.yml
22+
when: nginx_drupal_sites|lower != 'none'
23+
- name: "Validate configuration"
24+
shell: nginx -t

tasks/sites.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: "Create sites-enabled configuration directory"
3+
file: path={{nginx_drupal_config_path}}/sites-enabled state=directory
4+
- name: "Create available sites configuration files"
5+
template: src=sites-available/drupal-site.j2 dest={{nginx_drupal_config_path}}/sites-available/{{item.file_name}}.conf
6+
with_items: nginx_drupal_sites
7+
- name: "Create enabled sites symlinks"
8+
file: path={{nginx_drupal_config_path}}/sites-enabled/{{item.file_name}}.conf src={{nginx_drupal_config_path}}/sites-available/{{item.file_name}}.conf state=link
9+
with_items: nginx_drupal_sites
10+
when: item.enabled|default(True)
11+
notify:
12+
- reload nginx
13+
- name: "Remove disabled sites symlinks"
14+
file: path={{nginx_drupal_config_path}}/sites-enabled/{{item.file_name}}.conf state=absent
15+
with_items: nginx_drupal_sites
16+
when: item.enabled|default(True) == False
17+
notify:
18+
- reload nginx

0 commit comments

Comments
 (0)