mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c63efa588 | ||
|
|
3e228d0812 | ||
|
|
1e7a0fc855 | ||
|
|
93b90c748f | ||
|
|
d8f6088362 | ||
|
|
8c3b1c7f13 | ||
|
|
5cdd1a8b37 | ||
|
|
0363a37e06 | ||
|
|
a1e76453cf | ||
|
|
729173c46c | ||
|
|
2f8ce00067 | ||
|
|
9b286f9b96 | ||
|
|
4a2478a4fb | ||
|
|
a9a72dd25f | ||
|
|
2a612a55b9 | ||
|
|
1280a441ee | ||
|
|
21edb6b584 | ||
|
|
c524b97b0f | ||
|
|
993310641a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
*.swp
|
*.swp
|
||||||
*.retry
|
*.retry
|
||||||
*.pyc
|
*.pyc
|
||||||
|
/tests/HanXHX.php
|
||||||
|
|||||||
12
.travis.yml
12
.travis.yml
@@ -1,11 +1,12 @@
|
|||||||
env:
|
env:
|
||||||
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
|
||||||
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.6,<2.7'
|
||||||
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
|
||||||
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.7,<2.8'
|
||||||
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.8,<2.9'
|
||||||
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.8,<2.9'
|
||||||
|
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.9,<2.10'
|
||||||
|
- PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.9,<2.10'
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
@@ -15,7 +16,9 @@ sudo: required
|
|||||||
dist: trusty
|
dist: trusty
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
python: 2.7
|
python:
|
||||||
|
- 2.7
|
||||||
|
- 3.6
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
@@ -26,6 +29,7 @@ before_install:
|
|||||||
|
|
||||||
install:
|
install:
|
||||||
- pip install "$ANSIBLE_VERSION"
|
- pip install "$ANSIBLE_VERSION"
|
||||||
|
- ansible-galaxy install -p ./tests HanXHX.php,master
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
|
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -55,6 +55,7 @@ FreeBSD:
|
|||||||
- `nginx_error_log_level`: default log level
|
- `nginx_error_log_level`: default log level
|
||||||
- `nginx_auto_config_httpv2`: boolean, auto configure HTTP2 where possible
|
- `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_fastcgi_fix_realpath`: boolean, use realpath for fastcgi (fix problems with symlinks and PHP opcache)
|
||||||
|
- `nginx_default_hsts`: string, default header sent for HSTS
|
||||||
|
|
||||||
### Nginx Configuration
|
### Nginx Configuration
|
||||||
|
|
||||||
@@ -105,6 +106,16 @@ Dependencies
|
|||||||
|
|
||||||
None
|
None
|
||||||
|
|
||||||
|
|
||||||
|
If you need to dev this role locally
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
Before use vagrant, run once:
|
||||||
|
|
||||||
|
```
|
||||||
|
ansible-galaxy install -p ./tests/ HanXHX.php,master
|
||||||
|
```
|
||||||
|
|
||||||
Example Playbook
|
Example Playbook
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
|||||||
16
Vagrantfile
vendored
16
Vagrantfile
vendored
@@ -6,20 +6,18 @@
|
|||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
|
|
||||||
vms_debian = [
|
vms_debian = [
|
||||||
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.0"}] }},
|
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => {} },
|
||||||
{ :name => "debian-stretch-sury", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }},
|
{ :name => "debian-buster", :box => "debian/buster64", :vars => {} }
|
||||||
{ :name => "debian-buster", :box => "debian/buster64", :vars => { "nginx_php": [{"version": "7.3"}] }}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
vms_freebsd = [
|
vms_freebsd = [
|
||||||
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
|
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.3-STABLE", :vars => {} },
|
||||||
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
|
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.1-STABLE", :vars => {} }
|
||||||
]
|
]
|
||||||
|
|
||||||
conts = [
|
conts = [
|
||||||
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.0"}] }},
|
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => {} },
|
||||||
{ :name => "docker-debian-stretch-sury", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }},
|
{ :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => {} },
|
||||||
{ :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => { "nginx_php": [{"version": "7.3"}] }},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
config.vm.network "private_network", type: "dhcp"
|
config.vm.network "private_network", type: "dhcp"
|
||||||
@@ -66,7 +64,7 @@ Vagrant.configure("2") do |config|
|
|||||||
v.cpus = 2
|
v.cpus = 2
|
||||||
v.memory = 512
|
v.memory = 512
|
||||||
end
|
end
|
||||||
m.vm.provision "shell", inline: "pkg install -y python bash"
|
m.vm.provision "shell", inline: "[ -e /usr/local/bin/bash ] || pkg install -y python bash"
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ nginx_auto_config_httpv2: true
|
|||||||
nginx_default_site: null
|
nginx_default_site: null
|
||||||
nginx_default_site_ssl: null
|
nginx_default_site_ssl: null
|
||||||
nginx_fastcgi_fix_realpath: true
|
nginx_fastcgi_fix_realpath: true
|
||||||
|
nginx_default_hsts: 'max-age=63072000; includeSubDomains'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nginx directories
|
# Nginx directories
|
||||||
@@ -84,6 +85,18 @@ nginx_http_gzip_disable: '"msie6"'
|
|||||||
#
|
#
|
||||||
nginx_custom_http: []
|
nginx_custom_http: []
|
||||||
|
|
||||||
|
#
|
||||||
|
# Nginx default
|
||||||
|
#
|
||||||
|
nginx_default_listen:
|
||||||
|
- '80'
|
||||||
|
- '[::]:80'
|
||||||
|
nginx_default_listen_ssl:
|
||||||
|
- '443'
|
||||||
|
- '[::]:443'
|
||||||
|
nginx_default_listen_proxy_protocol: []
|
||||||
|
nginx_default_listen_proxy_protocol_ssl: []
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sites
|
# Sites
|
||||||
#
|
#
|
||||||
@@ -115,7 +128,7 @@ nginx_load_modules: []
|
|||||||
#
|
#
|
||||||
nginx_dh: null
|
nginx_dh: null
|
||||||
nginx_dh_path: '{{ nginx_ssl_dir }}/dhparam.pem'
|
nginx_dh_path: '{{ nginx_ssl_dir }}/dhparam.pem'
|
||||||
nginx_dh_length: 4096
|
nginx_dh_length: 2048
|
||||||
|
|
||||||
#
|
#
|
||||||
# acme.sh
|
# acme.sh
|
||||||
|
|||||||
13
doc/php.md
13
doc/php.md
@@ -2,8 +2,7 @@ PHP
|
|||||||
===
|
===
|
||||||
|
|
||||||
`nginx_php`:
|
`nginx_php`:
|
||||||
- `version`: (M) PHP version
|
- `upstream_name` (M)
|
||||||
- `upstream_name` (O)
|
|
||||||
- `sockets`: (O) socket list
|
- `sockets`: (O) socket list
|
||||||
|
|
||||||
If `sockets` is not provided, if uses local unix socket (based on PHP version).
|
If `sockets` is not provided, if uses local unix socket (based on PHP version).
|
||||||
@@ -16,8 +15,8 @@ Each socket have:
|
|||||||
|
|
||||||
XOR
|
XOR
|
||||||
|
|
||||||
- `host`
|
- `host` (M)
|
||||||
- `port`
|
- `port` (M)
|
||||||
- `weight`
|
- `weight` (O)
|
||||||
- `max_fails`
|
- `max_fails` (O)
|
||||||
- `fail_timeout`
|
- `fail_timeout` (O)
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ Common
|
|||||||
- `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.
|
- `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. Optional when `proto` contains "https". If you don't set this value, it will search by `name`.
|
- `ssl_name`: (D) name of the key used when using TLS/SSL. Optional when `proto` contains "https". If you don't set this value, it will search by `name`.
|
||||||
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
|
- `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)
|
- `listen_proxy_protocol` (O) Enable proxy protocol on http port.
|
||||||
- `http_proxy_protocol_port` (O) Enable proxy protocol on http port.
|
- `listen_proxy_protocol_ssl` (O) Enable proxy protocol on https port.
|
||||||
- `https_proxy_protocol_port` (O) Enable proxy protocol on https port.
|
- `hsts` (O) overwrite default header for hsts
|
||||||
|
|
||||||
(O): Optional
|
(O): Optional
|
||||||
(M): Mandatory
|
(M): Mandatory
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
def nginx_site_filename(site):
|
def nginx_site_filename(site):
|
||||||
if site.has_key('filename'):
|
if 'filename' in site:
|
||||||
return site['filename']
|
return site['filename']
|
||||||
else:
|
else:
|
||||||
return nginx_site_name(site)
|
return nginx_site_name(site)
|
||||||
@@ -14,17 +14,45 @@ def nginx_ssl_dir(pair, ssl_dir):
|
|||||||
return ssl_dir + '/' + nginx_site_filename(pair)
|
return ssl_dir + '/' + nginx_site_filename(pair)
|
||||||
|
|
||||||
def nginx_key_path(pair, ssl_dir):
|
def nginx_key_path(pair, ssl_dir):
|
||||||
if pair.has_key('dest_key'):
|
if 'dest_key' in pair:
|
||||||
return pair['dest_key']
|
return pair['dest_key']
|
||||||
else:
|
else:
|
||||||
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.key'
|
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.key'
|
||||||
|
|
||||||
def nginx_cert_path(pair, ssl_dir):
|
def nginx_cert_path(pair, ssl_dir):
|
||||||
if pair.has_key('dest_cert'):
|
if 'dest_cert' in pair:
|
||||||
return pair['dest_cert']
|
return pair['dest_cert']
|
||||||
else:
|
else:
|
||||||
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.crt'
|
return nginx_ssl_dir(pair, ssl_dir) + '/' + nginx_site_filename(pair) + '.crt'
|
||||||
|
|
||||||
|
def nginx_all_site_names(site):
|
||||||
|
all_sites = []
|
||||||
|
if isinstance(site['name'], list):
|
||||||
|
all_sites = all_sites + site['name']
|
||||||
|
else:
|
||||||
|
all_sites.append(site['name'])
|
||||||
|
|
||||||
|
if 'redirect_from' in site:
|
||||||
|
if isinstance(site['redirect_from'], list):
|
||||||
|
all_sites = all_sites + site['redirect_from']
|
||||||
|
else:
|
||||||
|
all_sites.append(site['redirect_from'])
|
||||||
|
|
||||||
|
return all_sites
|
||||||
|
|
||||||
|
def nginx_search_by_ssl_name(sites, ssl_name):
|
||||||
|
if isinstance(ssl_name, list):
|
||||||
|
comp_ssl_name = ssl_name[0]
|
||||||
|
else:
|
||||||
|
comp_ssl_name = ssl_name
|
||||||
|
|
||||||
|
res = None
|
||||||
|
for site in sites:
|
||||||
|
if 'ssl_name' in site and site['ssl_name'] == comp_ssl_name:
|
||||||
|
res = site
|
||||||
|
break
|
||||||
|
return res
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' Nginx module '''
|
''' Nginx module '''
|
||||||
|
|
||||||
@@ -34,5 +62,7 @@ class FilterModule(object):
|
|||||||
'nginx_site_name': nginx_site_name,
|
'nginx_site_name': nginx_site_name,
|
||||||
'nginx_ssl_dir': nginx_ssl_dir,
|
'nginx_ssl_dir': nginx_ssl_dir,
|
||||||
'nginx_key_path': nginx_key_path,
|
'nginx_key_path': nginx_key_path,
|
||||||
'nginx_cert_path': nginx_cert_path
|
'nginx_cert_path': nginx_cert_path,
|
||||||
|
'nginx_all_site_names': nginx_all_site_names,
|
||||||
|
'nginx_search_by_ssl_name': nginx_search_by_ssl_name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,10 @@
|
|||||||
def php_default_upstream_socket(php_version):
|
def php_default_upstream_socket(php_version):
|
||||||
return '/run/php/php%s-fpm.sock' % php_version
|
return '/run/php/php%s-fpm.sock' % php_version
|
||||||
|
|
||||||
def php_default_upstream_name(php_version):
|
|
||||||
return 'default_php_%s' % php_version
|
|
||||||
|
|
||||||
def php_fpm_service(php_version):
|
|
||||||
return 'php%s-fpm' % php_version
|
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' PHP module '''
|
''' PHP module '''
|
||||||
|
|
||||||
def filters(self):
|
def filters(self):
|
||||||
return {
|
return {
|
||||||
'php_default_upstream_socket': php_default_upstream_socket,
|
'php_default_upstream_socket': php_default_upstream_socket,
|
||||||
'php_default_upstream_name': php_default_upstream_name,
|
|
||||||
'php_fpm_service': php_fpm_service,
|
|
||||||
'php_fpm_package': php_fpm_service
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
- name: APT | Install python-passlib
|
- name: APT | Install python-passlib
|
||||||
apt:
|
apt:
|
||||||
pkg: python-passlib
|
pkg: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}-passlib"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: STAT | Check acme.sh is installed
|
- name: STAT | Check acme.sh is installed
|
||||||
@@ -51,3 +51,4 @@
|
|||||||
creates: "{{ nginx_acmesh_dir }}"
|
creates: "{{ nginx_acmesh_dir }}"
|
||||||
|
|
||||||
when: not acme.stat.exists
|
when: not acme.stat.exists
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: SET_FACT | Assign default..
|
- name: SET_FACT | Assign default...
|
||||||
set_fact:
|
set_fact:
|
||||||
acme_create: []
|
acme_create: []
|
||||||
|
|
||||||
- name: STAT | Check if certificates are already installed
|
- name: STAT | Check if certificates are already installed
|
||||||
stat:
|
stat:
|
||||||
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt"
|
path: "{{ item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.acme is defined and item.acme
|
when: item.acme is defined and item.acme
|
||||||
register: acme_installed_certs
|
register: acme_installed_certs
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
set_fact:
|
set_fact:
|
||||||
acme_create: "{{ acme_create | default([]) + [ (item.item) ] }}"
|
acme_create: "{{ acme_create | default([]) + [ (item.item) ] }}"
|
||||||
loop: "{{ acme_installed_certs.results }}"
|
loop: "{{ acme_installed_certs.results }}"
|
||||||
when: item.skipped is not defined and not item.stat.exists
|
when: item.skipped is not defined and (not item.stat.exists or item.stat.size == 0)
|
||||||
|
|
||||||
- name: BLOCK | Start acme
|
- name: BLOCK | Start acme
|
||||||
block:
|
block:
|
||||||
@@ -50,11 +50,11 @@
|
|||||||
command: |
|
command: |
|
||||||
{{ nginx_acmesh_bin }}
|
{{ nginx_acmesh_bin }}
|
||||||
--home {{ nginx_acmesh_dir }}
|
--home {{ nginx_acmesh_dir }}
|
||||||
--issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %}
|
--issue{% for s in nginx_sites | nginx_search_by_ssl_name(item.name) | nginx_all_site_names %} -d {{ s }}{% endfor %}
|
||||||
--nginx
|
--nginx
|
||||||
{% if nginx_acmesh_test %}--test{% endif %}
|
{% if nginx_acmesh_test %}--test --log{% endif %}
|
||||||
args:
|
args:
|
||||||
creates: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
creates: "{{ nginx_acmesh_dir }}/{{ item | nginx_site_name }}/fullchain.cer"
|
||||||
loop: "{{ acme_create }}"
|
loop: "{{ acme_create }}"
|
||||||
register: acme_get
|
register: acme_get
|
||||||
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
||||||
@@ -69,12 +69,12 @@
|
|||||||
command: |
|
command: |
|
||||||
{{ nginx_acmesh_bin }}
|
{{ nginx_acmesh_bin }}
|
||||||
--home {{ nginx_acmesh_dir }}
|
--home {{ nginx_acmesh_dir }}
|
||||||
--install-cert -d {{ item | nginx_site_name }}
|
--install-cert -d {{ nginx_sites | nginx_search_by_ssl_name(item | nginx_site_name) | nginx_site_name }}
|
||||||
--fullchain-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt
|
--fullchain-file {{ item | nginx_cert_path(nginx_ssl_dir) }}
|
||||||
--key-file {{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key
|
--key-file {{ item | nginx_key_path(nginx_ssl_dir) }}
|
||||||
--reloadcmd "service nginx reload"
|
--reloadcmd "service nginx reload"
|
||||||
args:
|
args:
|
||||||
creates: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.key"
|
creates: "{{ item | nginx_cert_path(nginx_ssl_dir) }}"
|
||||||
loop: "{{ nginx_ssl_pairs }}"
|
loop: "{{ nginx_ssl_pairs }}"
|
||||||
when: item.acme is defined and item.acme
|
when: item.acme is defined and item.acme
|
||||||
notify: restart nginx
|
notify: restart nginx
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
- block:
|
- block:
|
||||||
|
|
||||||
- name: STAT | Get info ajout DH file
|
- name: STAT | Get info about DH file
|
||||||
stat:
|
stat:
|
||||||
path: "{{ nginx_dh_path }}"
|
path: "{{ nginx_dh_path }}"
|
||||||
get_checksum: no
|
get_checksum: no
|
||||||
|
|||||||
@@ -4,15 +4,8 @@
|
|||||||
template:
|
template:
|
||||||
src: "etc/nginx/conf.d/php.conf.j2"
|
src: "etc/nginx/conf.d/php.conf.j2"
|
||||||
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
||||||
when: nginx_php | length > 0
|
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
- name: FILE | Delete PHP upstream
|
|
||||||
file:
|
|
||||||
path: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
|
||||||
state: absent
|
|
||||||
when: nginx_php | length == 0
|
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy other upstreams
|
- name: TEMPLATE | Deploy other upstreams
|
||||||
template:
|
template:
|
||||||
src: "etc/nginx/conf.d/_upstream.conf.j2"
|
src: "etc/nginx/conf.d/_upstream.conf.j2"
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
server {
|
{% set site = nginx_sites | nginx_search_by_ssl_name(item.name) %}
|
||||||
listen {{ item.acme_port | default('80') }};
|
{% set __listen = item.listen | default(nginx_default_listen) %}
|
||||||
listen [::]:{{ item.acme_port | default('80') }};
|
{% set __listen_proxy_protocol = item.listen_proxy_protocol | default(nginx_default_listen_proxy_protocol) %}
|
||||||
|
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(" ") }}{% endif %}{% if item.redirect_from is defined %} {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ item.redirect_from | join(" ") }}{% endif %}{% endif %};
|
server {
|
||||||
|
{% for port in __listen %}
|
||||||
|
listen {{ port }};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }} proxy_protocol;
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
server_name {{ site | nginx_all_site_names | join(" ") }};
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
return 503;
|
return 503;
|
||||||
|
|||||||
@@ -3,18 +3,27 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
{% for php in nginx_php %}
|
{% for php in nginx_php %}
|
||||||
upstream {{ php.upstream_name | default((php.version | php_default_upstream_name)) }} {
|
upstream {{ php.upstream_name }} {
|
||||||
{% for sock in php.sockets | default([]) %}
|
{% for sock in php.sockets | default([]) %}
|
||||||
{% if sock.host is defined %}
|
{% if sock.host is defined %}
|
||||||
server {{ sock.host }}:{{ sock.port }} weight={{ sock.weight | default('1') }} max_fails={{ sock.max_fails | default('5') }} fail_timeout={{ sock.fail_timeout | default('10s') }};
|
server {{ sock.host }}:{{ sock.port }} weight={{ sock.weight | default('1') }} max_fails={{ sock.max_fails | default('5') }} fail_timeout={{ sock.fail_timeout | default('10s') }};
|
||||||
{% else %}
|
{% else %}
|
||||||
server unix:{{ sock.unix | default((php.version | php_default_upstream_socket)) }} weight={{ sock.weight | default('1') }};
|
server unix:{{ sock.unix }} weight={{ sock.weight | default('1') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
|
||||||
server unix:{{ php.version | php_default_upstream_socket }} weight=1;
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if ansible_local.hanxhx_php.fpm_pool is defined%}
|
||||||
|
# -------------------------------------------------------
|
||||||
|
# Auto-detected PHP config for HanXHX.php ansible role
|
||||||
|
# -------------------------------------------------------
|
||||||
|
|
||||||
|
{% for php in ansible_local.hanxhx_php.fpm_pool %}
|
||||||
|
upstream {{ php.name }} {
|
||||||
|
server {% if php.listen.startswith('/') %}unix:{{ php.listen }}{% else %}{{ php.listen }}{% endif %};
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
# vim:filetype=nginx
|
# vim:filetype=nginx
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ ssl_session_cache shared:SSL:10m;
|
|||||||
ssl_session_tickets off;
|
ssl_session_tickets off;
|
||||||
ssl_stapling on;
|
ssl_stapling on;
|
||||||
ssl_stapling_verify on;
|
ssl_stapling_verify on;
|
||||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
|
|
||||||
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||||
resolver_timeout {{ nginx_resolver_timeout }};
|
resolver_timeout {{ nginx_resolver_timeout }};
|
||||||
ssl_dhparam {{ nginx_dh_path }};
|
ssl_dhparam {{ nginx_dh_path }};
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ ssl_session_cache shared:SSL:10m;
|
|||||||
ssl_session_tickets off;
|
ssl_session_tickets off;
|
||||||
ssl_stapling on;
|
ssl_stapling on;
|
||||||
ssl_stapling_verify on;
|
ssl_stapling_verify on;
|
||||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
|
|
||||||
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||||
resolver_timeout {{ nginx_resolver_timeout }};
|
resolver_timeout {{ nginx_resolver_timeout }};
|
||||||
ssl_dhparam {{ nginx_dh_path }};
|
ssl_dhparam {{ nginx_dh_path }};
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
{% set __proto = item.proto | default(['http']) %}
|
{% set __proto = item.proto | default(['http']) %}
|
||||||
{% set __main_name = item | nginx_site_filename %}
|
{% set __main_name = item | nginx_site_name %}
|
||||||
{% set __listen = item.listen | default(['80', '[::]:80']) %}
|
{% set __listen = item.listen | default(nginx_default_listen) %}
|
||||||
{% set __listen_ssl = item.listen_ssl | default(['443', '[::]:443']) %}
|
{% set __listen_ssl = item.listen_ssl | default(nginx_default_listen_ssl) %}
|
||||||
{% set __http_proxy_protocol_port = item.http_proxy_protocol_port | default([]) %}
|
{% set __listen_proxy_protocol = item.listen_proxy_protocol | default(nginx_default_listen_proxy_protocol) %}
|
||||||
{% set __https_proxy_protocol_port = item.https_proxy_protocol_port | default([]) %}
|
{% set __listen_proxy_protocol_ssl = item.listen_proxy_protocol_ssl | default(nginx_default_listen_proxy_protocol_ssl) %}
|
||||||
{% set __location = item.location | default({}) %}
|
{% set __location = item.location | default({}) %}
|
||||||
{% set __location_before = item.location_before | default({}) %}
|
{% set __location_before = item.location_before | default({}) %}
|
||||||
{% set __headers = item.headers | default(nginx_servers_default_headers) %}
|
{% set __headers = item.headers | default(nginx_servers_default_headers) %}
|
||||||
{% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %}
|
{% set __ssl_name = item.ssl_name | default(__main_name) %}
|
||||||
{% set __location_order = item.location_order | default(__location.keys()) %}
|
{% set __location_order = item.location_order | default(__location.keys()) %}
|
||||||
{% set __location_order_before = item.location_order_before | default(__location_before.keys()) %}
|
{% set __location_order_before = item.location_order_before | default(__location_before.keys()) %}
|
||||||
|
{% set __http2 = nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %}
|
||||||
|
{% macro listen_http() %}
|
||||||
|
{% endmacro %}
|
||||||
{% macro server_name(name) %}
|
{% macro server_name(name) %}
|
||||||
{% if name is string %}{{ name }}{% else %}{{ name | join(" ") }}{% endif %}
|
{% if name is string %}{{ name }}{% else %}{{ name | join(" ") }}{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
@@ -40,7 +43,7 @@
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro ssl(ssl_name) %}
|
{% macro ssl(ssl_name) %}
|
||||||
{% for sn in nginx_ssl_pairs if ((sn.name is string and sn.name == ssl_name) or (sn.name.0 == ssl_name)) %}
|
{% for sn in nginx_ssl_pairs if (sn.name is defined and (sn | nginx_site_name) == ssl_name) %}
|
||||||
ssl_certificate {{ sn | nginx_cert_path(nginx_ssl_dir) }};
|
ssl_certificate {{ sn | nginx_cert_path(nginx_ssl_dir) }};
|
||||||
ssl_certificate_key {{ sn | nginx_key_path(nginx_ssl_dir) }};
|
ssl_certificate_key {{ sn | nginx_key_path(nginx_ssl_dir) }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -48,7 +51,10 @@
|
|||||||
{% macro httpsredirect(name) %}
|
{% macro httpsredirect(name) %}
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
server_name {{ server_name(name) }};
|
server_name {{ server_name(name) }};
|
||||||
location / {
|
location / {
|
||||||
@@ -67,16 +73,23 @@ server {
|
|||||||
server {
|
server {
|
||||||
{% if 'http' in __proto %}
|
{% if 'http' in __proto %}
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if nginx_default_site == __main_name %} default_server{% endif %}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }}{% if nginx_default_site == __main_name %} default_server{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }}{% if nginx_default_site == __main_name %} default_server{% endif %} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'https' in __proto %}
|
{% if 'https' in __proto %}
|
||||||
{% for port in __listen_ssl %}
|
{% for port in __listen_ssl %}
|
||||||
listen {{ port }}{% if nginx_default_site_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %}{% if port | int in __https_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }}{% if nginx_default_site_ssl == __main_name %} default_server{% endif %} ssl{% if __http2 %} http2{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol_ssl %}
|
||||||
|
listen {{ port }}{% if nginx_default_site_ssl == __main_name %} default_server{% endif %} ssl{% if __http2 %} http2{% endif %} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ ssl(__ssl_name) }}
|
{{ ssl(__ssl_name) }}
|
||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
|
add_header Strict-Transport-Security "{{ item.hsts | default(nginx_default_hsts) }}" always;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {{ server_name(item.name) }};
|
server_name {{ server_name(item.name) }};
|
||||||
@@ -84,7 +97,7 @@ server {
|
|||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
{% else %}
|
{% else %}
|
||||||
root {{ nginx_root }}/{{ __main_name }}/public;
|
root {{ nginx_root }}/{{ item | nginx_site_filename }}/public;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
@@ -105,15 +118,15 @@ server {
|
|||||||
|
|
||||||
{% block template_headers %}
|
{% block template_headers %}
|
||||||
# --> Custom headers
|
# --> Custom headers
|
||||||
{% for key, value in __headers.iteritems() %}
|
{% for key, value in __headers.items() %}
|
||||||
add_header {{ key }} "{{ value }}";
|
add_header {{ key }} "{{ value | regex_replace('\s+always$', '') }}"{% if value | regex_search('\s+always$') %} always{% endif %};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
# <-- Custom headers
|
# <-- Custom headers
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{{ locations(__location_before, __location_order_before) }}
|
{{ locations(__location_before, __location_order_before) }}
|
||||||
|
|
||||||
{% if not __location.has_key('/') %}
|
{% if not '/' in __location %}
|
||||||
location / {
|
location / {
|
||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files {{ item.override_try_files | default('$uri $uri/ =404') }};
|
try_files {{ item.override_try_files | default('$uri $uri/ =404') }};
|
||||||
@@ -182,26 +195,34 @@ server {
|
|||||||
#
|
#
|
||||||
server {
|
server {
|
||||||
{% for port in __listen %}
|
{% for port in __listen %}
|
||||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }};
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol %}
|
||||||
|
listen {{ port }} proxy_protocol;
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
server_name {{ server_name(item.redirect_from) }};
|
server_name {{ server_name(item.redirect_from) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
|
return 301 $scheme://{{ __main_name }}$request_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if 'https' in __proto %}
|
{% if 'https' in __proto %}
|
||||||
server {
|
server {
|
||||||
{% for port in __listen_ssl %}
|
{% for port in __listen_ssl %}
|
||||||
listen {{ port }}{% if nginx_default_site_ssl == __main_name %} default_server{% endif %} ssl{% if nginx_auto_config_httpv2 and 'http_v2' in nginx_modules %} http2{% endif %}{% if port | int in __https_proxy_protocol_port %} proxy_protocol{% endif %};
|
listen {{ port }} ssl{% if __http2 %} http2{% endif %};
|
||||||
|
{% endfor %}
|
||||||
|
{% for port in __listen_proxy_protocol_ssl %}
|
||||||
|
listen {{ port }} ssl{% if __http2 %} http2{% endif %} proxy_protocol;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{{ ssl(__ssl_name) }}
|
{{ ssl(__ssl_name) }}
|
||||||
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
{% if item.ssl_template is not defined or item.ssl_template != false %}
|
||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
|
add_header Strict-Transport-Security "{{ item.hsts | default(nginx_default_hsts) }}" always;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {{ server_name(item.redirect_from) }};
|
server_name {{ server_name(item.redirect_from) }};
|
||||||
location / {
|
location / {
|
||||||
return 301 https://{{ item.name if item.name is string else item.name[0] }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
return 301 https://{{ __main_name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
{% if item.php_version is defined %}
|
|
||||||
{% set php_info = 'Explicit PHP version on site' %}
|
|
||||||
{% set php_upstream = (nginx_php|selectattr('version', 'equalto', item.php_version)|first).upstream_name | default(item.php_version | php_default_upstream_name) %}
|
|
||||||
{% elif item.php_upstream is defined %}
|
|
||||||
{% set php_info = 'Explicit Nginx/PHP upstream on site' %}
|
|
||||||
{% set php_upstream = item.php_upstream %}
|
|
||||||
{% else %}
|
|
||||||
{% set php_info = 'Warning: using first PHP version on config' %}
|
|
||||||
{% set php_upstream = nginx_php.0.upstream_name | default(nginx_php.0.version | php_default_upstream_name) %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% block template_index %}
|
{% block template_index %}
|
||||||
index {{ item.index | default('index.html index.htm index.php') }};
|
index {{ item.index | default('index.html index.htm index.php') }};
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -21,8 +10,7 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location ~ \.php$ {
|
location ~ \.php$ {
|
||||||
# {{ php_info }}
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
fastcgi_pass {{ php_upstream }};
|
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
{% for param in item.upstream_params %}
|
{% for param in item.upstream_params %}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
# {{ php_info }}
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
fastcgi_pass {{ php_upstream }};
|
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
{% for param in item.upstream_params %}
|
{% for param in item.upstream_params %}
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
|
|
||||||
{% block template_upstream_location %}
|
{% block template_upstream_location %}
|
||||||
location = /index.php {
|
location = /index.php {
|
||||||
# {{ php_info }}
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
fastcgi_pass {{ php_upstream }};
|
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||||
{% for param in item.upstream_params %}
|
{% for param in item.upstream_params %}
|
||||||
|
|||||||
27
templates/etc/nginx/sites-available/_symfony.j2
Normal file
27
templates/etc/nginx/sites-available/_symfony.j2
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{% extends "_php.j2" %}
|
||||||
|
|
||||||
|
{% block template_try_files %}
|
||||||
|
try_files $uri /index.php$is_args$args;
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_upstream_location %}
|
||||||
|
location /bundles {
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ ^/index\.php(/|$) {
|
||||||
|
fastcgi_pass {{ item.php_upstream }};
|
||||||
|
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 %}
|
||||||
|
include fastcgi.conf;
|
||||||
|
internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
return 404;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
@@ -6,24 +6,6 @@
|
|||||||
state: present
|
state: present
|
||||||
when: nginx_backports
|
when: nginx_backports
|
||||||
|
|
||||||
- block:
|
|
||||||
|
|
||||||
- name: APT | Install apt-transport-https
|
|
||||||
apt:
|
|
||||||
pkg: apt-transport-https
|
|
||||||
update_cache: yes
|
|
||||||
cache_valid_time: 3600
|
|
||||||
|
|
||||||
- name: APT_KEY | Install GPG key
|
|
||||||
apt_key:
|
|
||||||
url: 'https://packages.sury.org/php/apt.gpg'
|
|
||||||
|
|
||||||
- name: APT_REPOSITORY | Add APT repository
|
|
||||||
apt_repository:
|
|
||||||
repo: 'deb https://packages.sury.org/php {{ ansible_distribution_release }} main'
|
|
||||||
|
|
||||||
when: sury | default(false)
|
|
||||||
|
|
||||||
- name: APT | Install needed packages
|
- name: APT | Install needed packages
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ packages }}"
|
pkg: "{{ packages }}"
|
||||||
@@ -44,12 +26,19 @@
|
|||||||
|
|
||||||
- name: APT | Install PHP
|
- name: APT | Install PHP
|
||||||
apt:
|
apt:
|
||||||
pkg: "{{ item.version | php_fpm_package }}"
|
pkg: "{{ pkgs }}"
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
state: present
|
state: present
|
||||||
loop: "{{ nginx_php }}"
|
vars:
|
||||||
register: apt_php
|
pkgs:
|
||||||
|
- php-cli
|
||||||
|
- php-fpm
|
||||||
|
|
||||||
|
- name: SHELL | Get current PHP version
|
||||||
|
shell: php --version | awk '/^PHP/ { print $2 }' | grep -o -E '^.{3}'
|
||||||
|
changed_when: false
|
||||||
|
register: cur_php_version
|
||||||
|
|
||||||
- name: SERVICE | Force start fcgiwrap
|
- name: SERVICE | Force start fcgiwrap
|
||||||
service:
|
service:
|
||||||
@@ -58,11 +47,10 @@
|
|||||||
|
|
||||||
# Bypasses Ansible+Docker issue. With service module... php is not really started!
|
# Bypasses Ansible+Docker issue. With service module... php is not really started!
|
||||||
- name: COMMAND | Force start PHP
|
- name: COMMAND | Force start PHP
|
||||||
command: "service {{ item.version | php_fpm_service }} start"
|
command: "service php{{ cur_php_version.stdout }}-fpm start"
|
||||||
args:
|
args:
|
||||||
creates: "{{ item.version | php_default_upstream_socket }}"
|
creates: "/run/php/php{{ cur_php_version.stdout }}-fpm.pid"
|
||||||
warn: false
|
warn: false
|
||||||
loop: "{{ nginx_php }}"
|
|
||||||
|
|
||||||
- name: GET_URL | Download ngrok
|
- name: GET_URL | Download ngrok
|
||||||
get_url:
|
get_url:
|
||||||
@@ -78,3 +66,24 @@
|
|||||||
- name: SET_FACT | ngrok_path
|
- name: SET_FACT | ngrok_path
|
||||||
set_fact:
|
set_fact:
|
||||||
ngrok_path: '/tmp/ngrok'
|
ngrok_path: '/tmp/ngrok'
|
||||||
|
|
||||||
|
- name: USER | Create PHP User foo
|
||||||
|
user:
|
||||||
|
name: foo
|
||||||
|
system: yes
|
||||||
|
|
||||||
|
- name: INCLUDE_ROLE | HanXHX.php
|
||||||
|
include_role:
|
||||||
|
name: "{{ playbook_dir }}/HanXHX.php"
|
||||||
|
vars:
|
||||||
|
php_version: "{{ cur_php_version.stdout }}"
|
||||||
|
php_autoremove_default_pool: false
|
||||||
|
php_fpm_poold:
|
||||||
|
- name: 'hx_unix'
|
||||||
|
user: 'foo'
|
||||||
|
php_value:
|
||||||
|
display_errors: 'Off'
|
||||||
|
php_admin_value:
|
||||||
|
memory_limit: '98M'
|
||||||
|
- name: 'hx_ip'
|
||||||
|
listen: '127.0.0.1:9636'
|
||||||
|
|||||||
@@ -5,12 +5,20 @@
|
|||||||
nginx_pkgng_package: 'nginx-full'
|
nginx_pkgng_package: 'nginx-full'
|
||||||
nginx_user: 'www'
|
nginx_user: 'www'
|
||||||
nginx_php:
|
nginx_php:
|
||||||
- version: '7.2'
|
- upstream_name: 'manual'
|
||||||
sockets:
|
sockets:
|
||||||
- host: '127.0.0.1'
|
- host: '127.0.0.1'
|
||||||
port: 9000
|
port: 9000
|
||||||
nginx_load_modules:
|
- upstream_name: 'hx_unix'
|
||||||
- /usr/local/libexec/nginx/ngx_http_geoip_module.so
|
sockets:
|
||||||
|
- host: '127.0.0.1'
|
||||||
|
port: 9000
|
||||||
|
- upstream_name: 'hx_ip'
|
||||||
|
sockets:
|
||||||
|
- host: '127.0.0.1'
|
||||||
|
port: 9000
|
||||||
|
# nginx_load_modules:
|
||||||
|
# - /usr/local/libexec/nginx/ngx_http_geoip_module.so
|
||||||
ngrok_path: '/usr/local/bin/ngrok'
|
ngrok_path: '/usr/local/bin/ngrok'
|
||||||
|
|
||||||
- name: PKGNG | Install needed packages
|
- name: PKGNG | Install needed packages
|
||||||
@@ -22,16 +30,16 @@
|
|||||||
- curl
|
- curl
|
||||||
- daemonize
|
- daemonize
|
||||||
- fcgiwrap
|
- fcgiwrap
|
||||||
- GeoIP
|
# - GeoIP
|
||||||
- jq
|
- jq
|
||||||
- nghttp2
|
- nghttp2
|
||||||
- php72
|
- php74
|
||||||
- vim
|
- vim
|
||||||
|
|
||||||
- name: COMMAND | Get geoip database
|
#- name: COMMAND | Get geoip database
|
||||||
command: geoipupdate.sh
|
# command: geoipupdate.sh
|
||||||
args:
|
# args:
|
||||||
creates: /usr/local/share/GeoIP/GeoIP.dat
|
# creates: /usr/local/share/GeoIP/GeoIP.dat
|
||||||
|
|
||||||
- name: SERVICE | Force start services
|
- name: SERVICE | Force start services
|
||||||
service:
|
service:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: SHELL | Start ngrok
|
- name: SHELL | Start ngrok
|
||||||
shell: daemonize -l /tmp/ngrok.lock {{ ngrok_path }} http 8888 -bind-tls=false
|
shell: daemonize -l /tmp/ngrok.lock {{ ngrok_path }} http 80 -bind-tls=false
|
||||||
failed_when: false
|
failed_when: false
|
||||||
changed_when: ngrok.stderr.find("Can't lock the lock file") == -1
|
changed_when: ngrok.stderr.find("Can't lock the lock file") == -1
|
||||||
register: ngrok
|
register: ngrok
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
- hosts: all
|
- hosts: all
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
|
|
||||||
- name: INCLUDE_TASKS | Pre_tasks related to OS version
|
- name: INCLUDE_TASKS | Pre_tasks related to OS version
|
||||||
include_tasks: "includes/pre_{{ ansible_distribution }}.yml"
|
include_tasks: "includes/pre_{{ ansible_distribution }}.yml"
|
||||||
|
|
||||||
@@ -77,14 +78,14 @@
|
|||||||
nginx_acmesh: true
|
nginx_acmesh: true
|
||||||
nginx_acmesh_test: true
|
nginx_acmesh_test: true
|
||||||
nginx_ssl_pairs:
|
nginx_ssl_pairs:
|
||||||
- name:
|
- name: '{{ ngrok.stdout }}'
|
||||||
- '{{ ngrok.stdout }}'
|
|
||||||
acme: true
|
acme: true
|
||||||
acme_port: 8888
|
|
||||||
- name: 'test-ssl-selfsigned.local'
|
- name: 'test-ssl-selfsigned.local'
|
||||||
self_signed: true
|
self_signed: true
|
||||||
force: false
|
force: false
|
||||||
- name: 'test-ssl-predeployed.local'
|
- name:
|
||||||
|
- 'test-ssl-predeployed.local'
|
||||||
|
- 'test-multiple-name.local' # Hack: tests for acme with multiple name, without using acme
|
||||||
dest_key: "{{ int_ansible_ssl_dir }}/test.key"
|
dest_key: "{{ int_ansible_ssl_dir }}/test.key"
|
||||||
dest_cert: "{{ int_ansible_ssl_dir }}/test.crt"
|
dest_cert: "{{ int_ansible_ssl_dir }}/test.crt"
|
||||||
- name: 'test-ssl.local'
|
- name: 'test-ssl.local'
|
||||||
@@ -145,7 +146,7 @@
|
|||||||
- ' DZ no;'
|
- ' DZ no;'
|
||||||
- ' TN no;'
|
- ' TN no;'
|
||||||
- '}'
|
- '}'
|
||||||
nginx_default_site: 'first-test'
|
nginx_default_site: 'test.local'
|
||||||
nginx_default_site_ssl: 'test-ssl-predeployed.local'
|
nginx_default_site_ssl: 'test-ssl-predeployed.local'
|
||||||
nginx_sites:
|
nginx_sites:
|
||||||
- name:
|
- name:
|
||||||
@@ -154,7 +155,7 @@
|
|||||||
- 'test2-alias.local'
|
- 'test2-alias.local'
|
||||||
template: '_base'
|
template: '_base'
|
||||||
filename : 'first-test'
|
filename : 'first-test'
|
||||||
override_try_files: '$uri $uri /index.htm /index.html'
|
override_try_files: '$uri/ $uri =404'
|
||||||
headers:
|
headers:
|
||||||
'X-Frame-Options': 'deny always'
|
'X-Frame-Options': 'deny always'
|
||||||
'X-ansible-default': '1'
|
'X-ansible-default': '1'
|
||||||
@@ -203,7 +204,7 @@
|
|||||||
- '/'
|
- '/'
|
||||||
- '/a'
|
- '/a'
|
||||||
- name: 'test-php.local'
|
- name: 'test-php.local'
|
||||||
php_version: "{{ nginx_php.1.version if nginx_php.1 is defined else nginx_php.0.version }}"
|
php_upstream: "manual"
|
||||||
upstream_params:
|
upstream_params:
|
||||||
- 'fastcgi_param FOO bar;'
|
- 'fastcgi_param FOO bar;'
|
||||||
redirect_from:
|
redirect_from:
|
||||||
@@ -213,8 +214,10 @@
|
|||||||
use_access_log: true
|
use_access_log: true
|
||||||
- name: 'test-php-index.local'
|
- name: 'test-php-index.local'
|
||||||
template: '_php_index'
|
template: '_php_index'
|
||||||
|
php_upstream: 'hx_unix'
|
||||||
- name: 'test-php-index2.local'
|
- name: 'test-php-index2.local'
|
||||||
template: '_php_index2'
|
template: '_php_index2'
|
||||||
|
php_upstream: 'hx_ip'
|
||||||
- name: 'test-proxy.local'
|
- name: 'test-proxy.local'
|
||||||
listen:
|
listen:
|
||||||
- 8080
|
- 8080
|
||||||
@@ -232,9 +235,12 @@
|
|||||||
- name: 'test-ssl.local'
|
- name: 'test-ssl.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
- name: 'test-ssl-selfsigned.local'
|
- name:
|
||||||
|
- 'test-ssl-selfsigned.local'
|
||||||
|
- 'www.test-ssl-selfsigned.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
|
hsts: 'max-age=1664;'
|
||||||
- name: 'test-ssl-predeployed.local'
|
- name: 'test-ssl-predeployed.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
template: '_base'
|
template: '_base'
|
||||||
@@ -260,18 +266,22 @@
|
|||||||
- 'www.test-ssl-redirect-many2.local'
|
- 'www.test-ssl-redirect-many2.local'
|
||||||
- name: 'test-ssl-proxy-protocol.local'
|
- name: 'test-ssl-proxy-protocol.local'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
listen: [80, 20080]
|
listen_proxy_protocol: [20080]
|
||||||
listen_ssl: [443, 20443]
|
listen_proxy_protocol_ssl: [20443]
|
||||||
http_proxy_protocol_port: [20080]
|
|
||||||
https_proxy_protocol_port: [20443]
|
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: 'test-ssl.local'
|
ssl_name: 'test-ssl.local'
|
||||||
|
headers:
|
||||||
|
'X-Proxy-Protocol': '1'
|
||||||
- name: '{{ ngrok.stdout }}'
|
- name: '{{ ngrok.stdout }}'
|
||||||
proto: ['http', 'https']
|
proto: ['http', 'https']
|
||||||
|
listen_proxy_protocol: [21080]
|
||||||
|
listen_proxy_protocol_ssl: [21443]
|
||||||
template: '_base'
|
template: '_base'
|
||||||
ssl_name: '{{ ngrok.stdout }}'
|
ssl_name: '{{ ngrok.stdout }}'
|
||||||
headers:
|
headers:
|
||||||
'X-acme': '1'
|
'X-acme': '1'
|
||||||
|
|
||||||
|
nginx_php: "{{ [{'upstream_name': 'manual', 'sockets': [{'host': '127.0.0.1', 'port': '9636' }] }] }}"
|
||||||
nginx_dh_length: 1024
|
nginx_dh_length: 1024
|
||||||
roles:
|
roles:
|
||||||
- ../../
|
- ../../
|
||||||
@@ -372,7 +382,7 @@
|
|||||||
when: >
|
when: >
|
||||||
item.template is defined and
|
item.template is defined and
|
||||||
(item.template == '_php' or item.template == '_php_index' or item.template == '_php_index2')
|
(item.template == '_php' or item.template == '_php_index' or item.template == '_php_index2')
|
||||||
failed_when: p.content.find('PHP Version ' + item.php_version if 'php_version' in item else nginx_php.0.version) == -1
|
failed_when: p.content.find('PHP Version') == -1
|
||||||
|
|
||||||
- name: -- VERIFY INDEX2 --
|
- name: -- VERIFY INDEX2 --
|
||||||
uri:
|
uri:
|
||||||
@@ -511,6 +521,35 @@
|
|||||||
register: notdefaultssl
|
register: notdefaultssl
|
||||||
failed_when: notdefaultssl.x_ansible_default is defined
|
failed_when: notdefaultssl.x_ansible_default is defined
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------
|
||||||
|
# Check Proxy protocol
|
||||||
|
# --------------------------------
|
||||||
|
|
||||||
|
# Note: Debian Stretch doesn't any version of curl with "--haproxy-protocol" argument
|
||||||
|
|
||||||
|
- block:
|
||||||
|
|
||||||
|
- name: SHELL | Check HTTP proxy protocol
|
||||||
|
shell: curl -I --haproxy-protocol http://test-ssl-proxy-protocol.local:20080 | grep -qi 'X-Proxy-Protocol'
|
||||||
|
args:
|
||||||
|
executable: /bin/sh
|
||||||
|
warn: no
|
||||||
|
changed_when: false
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
|
- name: SHELL | Check HTTPS proxy protocol
|
||||||
|
shell: curl -I --haproxy-protocol -k https://test-ssl-proxy-protocol.local:20443 | grep -qi 'X-Proxy-Protocol'
|
||||||
|
args:
|
||||||
|
executable: /bin/sh
|
||||||
|
warn: no
|
||||||
|
changed_when: false
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|
||||||
|
when: not (ansible_distribution == 'Debian' and ansible_distribution_major_version is version('9', 'eq'))
|
||||||
|
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
# Check HTTP2
|
# Check HTTP2
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|||||||
@@ -46,6 +46,6 @@ nginx_templates_no_dir:
|
|||||||
nginx_servers_default_headers:
|
nginx_servers_default_headers:
|
||||||
'X-Frame-Options': 'DENY always'
|
'X-Frame-Options': 'DENY always'
|
||||||
'X-Content-Type-Options': 'nosniff always'
|
'X-Content-Type-Options': 'nosniff always'
|
||||||
'X-XSS-Protection': '1; mode=block'
|
'X-XSS-Protection': '1; mode=block always'
|
||||||
|
|
||||||
nginx_acmesh_bin: "{{ nginx_acmesh_dir }}/acme.sh"
|
nginx_acmesh_bin: "{{ nginx_acmesh_dir }}/acme.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user