mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4aeec0a94 | ||
|
|
713a2241de | ||
|
|
6cae501266 | ||
|
|
dd7834e8ce | ||
|
|
cb031c4014 | ||
|
|
db97fe84f8 | ||
|
|
c9629e385f | ||
|
|
5843d695b3 | ||
|
|
8c7d581131 | ||
|
|
0b85d81991 | ||
|
|
7fe08beb9a | ||
|
|
33ef161623 | ||
|
|
c2685732a4 | ||
|
|
737dfbeb30 | ||
|
|
def13392a7 | ||
|
|
6897f66344 |
16
.travis.yml
16
.travis.yml
@@ -12,14 +12,20 @@ env:
|
||||
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- env: PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- env: PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- env: PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- env: PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- env: PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.4,<2.5'
|
||||
- env: PLATFORM='docker-debian-jessie' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- env: PLATFORM='docker-debian-jessie-backports' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- env: PLATFORM='docker-debian-jessie-dotdeb' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- env: PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
- env: PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.5b,<2.6'
|
||||
|
||||
fast_finish: true
|
||||
|
||||
sudo: required
|
||||
|
||||
16
README.md
16
README.md
@@ -18,6 +18,15 @@ Features:
|
||||
- Can listen with proxy protocol
|
||||
- Generate certificates with acme.sh (let's encrypt) -- *EXPERIMENTAL*
|
||||
|
||||
Supported OS:
|
||||
|
||||
| OS | Working | Stable (active support) |
|
||||
| ------------------ | ------- | ----------------------- |
|
||||
| Debian Jessie (8) | Yes | Yes |
|
||||
| Debian Stretch (9) | Yes | Yes |
|
||||
| FreeBSD 11 | Yes | No |
|
||||
| FreeBSD 12 | Yes | No |
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
@@ -54,7 +63,12 @@ FreeBSD:
|
||||
- `nginx_events_*`: all variables in events block
|
||||
- `nginx_http_*`: all variables in http block
|
||||
- `nginx_custom_http`: instructions list (will put data in `/etc/nginx/conf.d/custom.conf`)
|
||||
- `nginx_module_packages`: package list module to install
|
||||
- `nginx_module_packages`: package list module to install (Debian)
|
||||
- `nginx_load_modules`: module list to load (full path), should be used only on FreeBSD
|
||||
|
||||
### Misc
|
||||
|
||||
- `nginx_debug_role`: set _true_ if you need to see output of no\_log tasks
|
||||
|
||||
About modules
|
||||
-------------
|
||||
|
||||
50
Vagrantfile
vendored
50
Vagrantfile
vendored
@@ -14,7 +14,8 @@ Vagrant.configure("2") do |config|
|
||||
]
|
||||
|
||||
vms_freebsd = [
|
||||
{ :name => "freebsd-10.2", :box => "freebsd/FreeBSD-10.2-STABLE" }
|
||||
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
|
||||
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
|
||||
]
|
||||
|
||||
conts = [
|
||||
@@ -26,6 +27,7 @@ Vagrant.configure("2") do |config|
|
||||
]
|
||||
|
||||
config.vm.network "private_network", type: "dhcp"
|
||||
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
||||
|
||||
conts.each do |opts|
|
||||
config.vm.define opts[:name] do |m|
|
||||
@@ -38,7 +40,7 @@ Vagrant.configure("2") do |config|
|
||||
ansible.playbook = "tests/test.yml"
|
||||
ansible.verbose = 'vv'
|
||||
ansible.become = true
|
||||
ansible.extra_vars = opts[:vars]
|
||||
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -54,32 +56,28 @@ Vagrant.configure("2") do |config|
|
||||
ansible.playbook = "tests/test.yml"
|
||||
ansible.verbose = 'vv'
|
||||
ansible.become = true
|
||||
ansible.extra_vars = opts[:vars]
|
||||
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
vms_freebsd.each do |opts|
|
||||
config.vm.base_mac = "080027D14C66"
|
||||
config.vm.define opts[:name] do |m|
|
||||
m.vm.box = opts[:box]
|
||||
m.vm.provider "virtualbox" do |v, override|
|
||||
override.ssh.shell = "csh"
|
||||
v.cpus = 2
|
||||
v.memory = 512
|
||||
end
|
||||
m.vm.provision "shell", inline: "pkg install -y python bash"
|
||||
m.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "tests/test.yml"
|
||||
ansible.verbose = 'vv'
|
||||
ansible.become = true
|
||||
ansible.extra_vars = opts[:vars].merge({ "nginx_debug_role": true, "ansible_python_interpreter": '/usr/local/bin/python' })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# See: https://forums.freebsd.org/threads/52717/
|
||||
# vms_freebsd.each do |opts|
|
||||
# config.vm.define opts[:name] do |m|
|
||||
# m.vm.box = opts[:box]
|
||||
# m.vm.provider "virtualbox" do |v|
|
||||
# v.vm.cpus = 1
|
||||
# v.vm.memory = 256
|
||||
# v.vm.guest = :freebsd
|
||||
# v.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
|
||||
# v.vm.base_mac = "080027D14C66"
|
||||
# end
|
||||
# config.ssh.shell = "sh"
|
||||
# m.vm.provision "shell", inline: "pkg install -y python bash"
|
||||
# m.vm.provision "ansible" do |ansible|
|
||||
# ansible.playbook = "tests/test.yml"
|
||||
# ansible.verbose = 'vv'
|
||||
# ansible.become = true
|
||||
# ansible.extra_vars = {
|
||||
# ansible_python_interpreter: '/usr/local/bin/python'
|
||||
# }
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -108,6 +108,7 @@ nginx_ssl_pairs: []
|
||||
# Dynamic modules
|
||||
#
|
||||
nginx_module_packages: []
|
||||
nginx_load_modules: []
|
||||
|
||||
#
|
||||
# Diffie-Hellman
|
||||
@@ -124,9 +125,7 @@ nginx_acmesh_dir: "/opt/acme.sh"
|
||||
nginx_acmesh_git_dir: "/tmp/acme.sh"
|
||||
nginx_acmesh_test: false
|
||||
|
||||
# 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'
|
||||
#
|
||||
# Debug
|
||||
#
|
||||
nginx_debug_role: false
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
Freebsd
|
||||
=======
|
||||
|
||||
Limitations
|
||||
-----------
|
||||
|
||||
Due to Ansible + FreeBSD limitations (`ansible_processor_vcpus`), You must explicitely set `nginx_worker_processes`.
|
||||
|
||||
About modules
|
||||
-------------
|
||||
|
||||
Dynamic modules must be set with full path (see `nginx_load_modules` path).
|
||||
|
||||
Sites not tested
|
||||
----------------
|
||||
|
||||
- BackupPC
|
||||
- Nagios
|
||||
|
||||
@@ -43,7 +43,6 @@ 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
|
||||
|
||||
@@ -2,21 +2,35 @@
|
||||
|
||||
- name: reload nginx
|
||||
command: nginx -t
|
||||
notify: real-reload nginx
|
||||
notify:
|
||||
- real-reload nginx
|
||||
- docker reload nginx
|
||||
|
||||
- name: restart nginx
|
||||
command: nginx -t
|
||||
notify: real-restart nginx
|
||||
notify:
|
||||
- real-restart nginx
|
||||
- docker restart nginx
|
||||
|
||||
- name: real-reload nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
when: ansible_virtualization_type != 'docker'
|
||||
|
||||
- name: real-restart nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: restarted
|
||||
when: ansible_virtualization_type != 'docker'
|
||||
|
||||
- name: docker reload nginx
|
||||
command: service nginx reload
|
||||
when: ansible_virtualization_type == 'docker'
|
||||
|
||||
- name: docker restart nginx
|
||||
command: service nginx restart
|
||||
when: ansible_virtualization_type == 'docker'
|
||||
|
||||
- name: restart nginx freebsd
|
||||
service:
|
||||
|
||||
@@ -30,5 +30,15 @@
|
||||
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' ]
|
||||
-
|
||||
- '{{ nginx_etc_dir }}/fastcgi.conf'
|
||||
when: nginx_fastcgi_fix_realpath
|
||||
|
||||
- name: COPY | Add modules manually
|
||||
copy:
|
||||
content: |
|
||||
{% for m in nginx_load_modules %}
|
||||
load_module {{ m }};
|
||||
{% endfor %}
|
||||
dest: "{{ nginx_etc_dir }}/modules-enabled/000-modules.conf"
|
||||
notify: reload nginx
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
state: absent
|
||||
with_items: "{{ nginx_htpasswd }}"
|
||||
when: item.state is defined and item.state == 'absent'
|
||||
no_log: true
|
||||
no_log: not nginx_debug_role
|
||||
|
||||
- name: HTPASSWD | Manage files
|
||||
htpasswd:
|
||||
@@ -18,4 +18,4 @@
|
||||
- "{{ nginx_htpasswd }}"
|
||||
- users
|
||||
when: item.0.state is not defined or item.0.state == 'present'
|
||||
no_log: true
|
||||
no_log: not nginx_debug_role
|
||||
|
||||
@@ -40,3 +40,28 @@
|
||||
apt:
|
||||
pkg: python-passlib
|
||||
state: present
|
||||
|
||||
- name: STAT | Check acme.sh is installed
|
||||
stat:
|
||||
path: "{{ nginx_acmesh_dir }}"
|
||||
register: acme
|
||||
|
||||
- block:
|
||||
|
||||
- name: APT | Install git
|
||||
apt:
|
||||
pkg: git
|
||||
|
||||
- name: GIT | Get acme.sh
|
||||
git:
|
||||
repo: 'https://github.com/Neilpang/acme.sh.git'
|
||||
dest: '{{ nginx_acmesh_git_dir }}'
|
||||
update: no
|
||||
|
||||
- name: SHELL | Install acme.sh
|
||||
shell: ./acme.sh --install --home {{ nginx_acmesh_dir }} --cert-home {{ nginx_acmesh_dir }}
|
||||
args:
|
||||
chdir: "{{ nginx_acmesh_git_dir }}"
|
||||
creates: "{{ nginx_acmesh_dir }}"
|
||||
|
||||
when: not acme.stat.exists
|
||||
|
||||
@@ -5,10 +5,37 @@
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- acme.sh
|
||||
- "{{ nginx_pkgng_package }}"
|
||||
- py27-passlib
|
||||
- curl
|
||||
|
||||
#
|
||||
# Bypass https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=224166#c1
|
||||
#
|
||||
- block:
|
||||
|
||||
- name: COMMAND | Create /usr/local/etc/fdfs/http.conf
|
||||
command: touch /usr/local/etc/fdfs/http.conf
|
||||
args:
|
||||
creates: /usr/local/etc/fdfs/http.conf
|
||||
register: fd1
|
||||
|
||||
- name: LINEINFILE | Tune fdfs
|
||||
lineinfile:
|
||||
regexp: ^load_fdfs_parameters_from_tracker
|
||||
line: load_fdfs_parameters_from_tracker=false
|
||||
path: /usr/local/etc/fdfs/mod_fastdfs.conf
|
||||
register: fd2
|
||||
|
||||
- name: SERVICE | Restart nginx when fdfs is tuned
|
||||
service:
|
||||
name: nginx
|
||||
state: restarted
|
||||
when: fd1.changed or fd2.changed
|
||||
|
||||
when: true
|
||||
|
||||
- name: FILE | Create configuration dir (like Debian)
|
||||
file:
|
||||
path: "{{ nginx_etc_dir }}/{{ item }}"
|
||||
@@ -18,27 +45,6 @@
|
||||
- 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 }}"
|
||||
|
||||
@@ -1,33 +1,9 @@
|
||||
---
|
||||
|
||||
- name: APT | Install git
|
||||
apt: pkg=git
|
||||
|
||||
- name: SET_FACT | Assign default..
|
||||
set_fact:
|
||||
acme_create: []
|
||||
|
||||
- name: STAT | Check acme.sh is installed
|
||||
stat:
|
||||
path: "{{ nginx_acmesh_dir }}"
|
||||
register: acme
|
||||
|
||||
- block:
|
||||
|
||||
- name: GIT | Get acme.sh
|
||||
git:
|
||||
repo: 'https://github.com/Neilpang/acme.sh.git'
|
||||
dest: '{{ nginx_acmesh_git_dir }}'
|
||||
update: no
|
||||
|
||||
- name: SHELL | Install acme.sh
|
||||
shell: ./acme.sh --install --home {{ nginx_acmesh_dir }} --cert-home {{ nginx_acmesh_dir }}
|
||||
args:
|
||||
chdir: "{{ nginx_acmesh_git_dir }}"
|
||||
creates: "{{ nginx_acmesh_dir }}"
|
||||
|
||||
when: not acme.stat.exists
|
||||
|
||||
- name: STAT | Check if certificates are already installed
|
||||
stat:
|
||||
path: "{{ nginx_ssl_dir }}/{{ item | nginx_site_name }}/{{ item | nginx_site_name }}.crt"
|
||||
@@ -48,11 +24,15 @@
|
||||
with_items: "{{ acme_create }}"
|
||||
register: fake_site
|
||||
|
||||
- name: SERVICE | Reload nginx
|
||||
- name: SERVICE | Restart nginx
|
||||
service:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
when: fake_site.changed
|
||||
state: restarted
|
||||
when: fake_site.changed and ansible_virtualization_type != 'docker'
|
||||
|
||||
- name: COMMAND | Restart nginx
|
||||
command: service nginx restart
|
||||
when: fake_site.changed and ansible_virtualization_type == 'docker'
|
||||
|
||||
- name: SHELL | Get certificates
|
||||
shell: '{{ nginx_acmesh_bin }} --issue{% if item.name is string %} -d {{ item.name }}{% else %}{% for name in item.name %} -d {{ name }}{% endfor %}{% endif %} --nginx {% if nginx_acmesh_test %}--test{% endif %}'
|
||||
@@ -61,7 +41,7 @@
|
||||
with_items: "{{ acme_create }}"
|
||||
register: acme_get
|
||||
failed_when: acme_get.rc != 0 and acme_get.rc != 2
|
||||
no_log: true
|
||||
no_log: not nginx_debug_role
|
||||
|
||||
- name: FILE | Create SSL dir per site
|
||||
file:
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
state: directory
|
||||
with_items: "{{ nginx_ssl_pairs }}"
|
||||
when: item.dest_key is not defined or item.dest_cert is not defined
|
||||
no_log: true
|
||||
no_log: not nginx_debug_role
|
||||
|
||||
- name: COPY | Deploy SSL keys
|
||||
copy:
|
||||
@@ -32,7 +32,7 @@
|
||||
with_items: "{{ nginx_ssl_pairs }}"
|
||||
when: item.key is defined
|
||||
notify: restart nginx
|
||||
no_log: true
|
||||
no_log: not nginx_debug_role
|
||||
|
||||
- name: COPY | Deploy SSL certs
|
||||
copy:
|
||||
@@ -42,7 +42,7 @@
|
||||
with_items: "{{ nginx_ssl_pairs }}"
|
||||
when: item.cert is defined
|
||||
notify: restart nginx
|
||||
no_log: true
|
||||
no_log: not nginx_debug_role
|
||||
|
||||
- name: Check DH command status
|
||||
async_status:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% for php in nginx_php %}
|
||||
upstream {{ php.upstream_name | default((php.version | php_default_upstream_name)) }} {
|
||||
{% for sock in php.sockets | default([]) %}
|
||||
{% if php.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') }};
|
||||
{% else %}
|
||||
server unix:{{ sock.unix | default((php.version | php_default_upstream_socket)) }} weight={{ sock.weight | default('1') }};
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
#
|
||||
|
||||
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_protocols TLSv1 TLSv1.1 TLSv1.2{% if nginx_version.stdout | version_compare('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
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;
|
||||
{% endif %}
|
||||
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||
resolver_timeout {{ nginx_resolver_timeout }};
|
||||
ssl_dhparam {{ nginx_dh_path }};
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
#
|
||||
|
||||
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2{% if nginx_version.stdout | version_compare('1.13.0', 'ge') %} TLSv1.3{% endif %};
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
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;
|
||||
{% endif %}
|
||||
resolver {{ nginx_resolver_hosts | join(' ') }} valid={{ nginx_resolver_valid }};
|
||||
resolver_timeout {{ nginx_resolver_timeout }};
|
||||
ssl_dhparam {{ nginx_dh_path }};
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
{% block template_upstream_location %}
|
||||
location ~ \.cgi$ {
|
||||
gzip off;
|
||||
include {{ nginx_etc_dir }}/fastcgi_params;
|
||||
include fastcgi.conf;
|
||||
fastcgi_pass unix:/var/run/fcgiwrap.socket;
|
||||
fastcgi_index BackupPC_Admin;
|
||||
fastcgi_param SCRIPT_FILENAME /usr/share/backuppc/cgi-bin$fastcgi_script_name;
|
||||
|
||||
@@ -28,7 +28,9 @@ server {
|
||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||
{% endfor %}
|
||||
server_name {{ name }};
|
||||
location / {
|
||||
return 301 https://{{ name }}{% if '443' not in __listen_ssl and 443 not in __listen_ssl %}:{{ __listen_ssl[0] }}{% endif %}$request_uri;
|
||||
}
|
||||
}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -170,8 +172,27 @@ server {
|
||||
listen {{ port }}{% if port | int in __http_proxy_protocol_port %} proxy_protocol{% endif %};
|
||||
{% endfor %}
|
||||
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
||||
location / {
|
||||
return 301 $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
{% if 'https' in __proto %}
|
||||
server {
|
||||
{% 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 %};
|
||||
{% endfor %}
|
||||
{{ ssl(__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 %}
|
||||
server_name {% if item.redirect_from is string %}{{ item.redirect_from }}{% else %}{{ "\n\t\t" }}{{ item.redirect_from | join("\n\t\t") }}{% endif %};
|
||||
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;
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
# vim:filetype=nginx
|
||||
|
||||
@@ -46,11 +46,7 @@
|
||||
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:{{ nginx_fcgiwrap_sock }};
|
||||
fastcgi_param AUTH_USER $remote_user;
|
||||
fastcgi_param REMOTE_USER $remote_user;
|
||||
@@ -58,10 +54,6 @@
|
||||
location ~ \.php$ {
|
||||
fastcgi_pass {{ php_upstream }};
|
||||
fastcgi_index index.php;
|
||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||
include fastcgi_params;
|
||||
{% else %}
|
||||
include fastcgi.conf;
|
||||
{% endif %}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
{% 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 %}
|
||||
@@ -29,10 +29,6 @@
|
||||
{{ param }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||
include fastcgi_params;
|
||||
{% else %}
|
||||
include fastcgi.conf;
|
||||
{% endif %}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
{{ param }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||
include fastcgi_params;
|
||||
{% else %}
|
||||
include fastcgi.conf;
|
||||
{% endif %}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -14,10 +14,6 @@
|
||||
{{ param }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
|
||||
include fastcgi_params;
|
||||
{% else %}
|
||||
include fastcgi.conf;
|
||||
{% endif %}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
install_recommends: no
|
||||
with_items:
|
||||
- backuppc
|
||||
# - owncloud
|
||||
|
||||
- name: APT | Install nagios3 (only on old Debian releases)
|
||||
apt:
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
---
|
||||
|
||||
- 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 }}"
|
||||
#- 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. :/
|
||||
|
||||
@@ -94,25 +94,6 @@
|
||||
dest: "/tmp"
|
||||
remote_src: yes
|
||||
|
||||
- name: SHELL | Check if ngrok is started
|
||||
shell: ps aux | grep -q [n]grok
|
||||
register: psngrok
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- block:
|
||||
|
||||
- name: SHELL | Start ngrok
|
||||
shell: daemonize /tmp/ngrok http 8888 -bind-tls=false
|
||||
|
||||
- name: WAIT_FOR | ngrok started
|
||||
wait_for:
|
||||
delay: 2
|
||||
port: 4040
|
||||
|
||||
when: psngrok.rc > 0
|
||||
|
||||
- name: SHELL | Get ngrok public address
|
||||
shell: curl 'http://127.0.0.1:4040/api/tunnels/command_line' | jq '.public_url' | grep -oE '[[:alnum:]]+\.ngrok\.io'
|
||||
register: ngrok
|
||||
changed_when: false
|
||||
- name: SET_FACT | ngrok_path
|
||||
set_fact:
|
||||
ngrok_path: '/tmp/ngrok'
|
||||
|
||||
@@ -2,23 +2,35 @@
|
||||
|
||||
- name: SET_FACT | FreeBSD web user
|
||||
set_fact:
|
||||
nginx_pkgng_package: 'nginx-devel'
|
||||
nginx_pkgng_package: 'nginx-full'
|
||||
nginx_user: 'www'
|
||||
nginx_php:
|
||||
- version: '5.6'
|
||||
- version: '7.2'
|
||||
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'
|
||||
|
||||
- name: PKGNG | Install needed packages
|
||||
pkgng:
|
||||
pkg: "{{ item }}"
|
||||
state: present
|
||||
with_items:
|
||||
- php56
|
||||
- curl
|
||||
- daemonize
|
||||
- fcgiwrap
|
||||
- GeoIP
|
||||
- jq
|
||||
- nghttp2
|
||||
- php72
|
||||
- vim
|
||||
|
||||
- name: COMMAND | Get geoip database
|
||||
command: geoipupdate.sh
|
||||
args:
|
||||
creates: /usr/local/share/GeoIP/GeoIP.dat
|
||||
|
||||
- name: SERVICE | Force start services
|
||||
service:
|
||||
@@ -29,3 +41,25 @@
|
||||
with_items:
|
||||
- php-fpm
|
||||
- fcgiwrap
|
||||
|
||||
- name: STAT | Check ports
|
||||
stat:
|
||||
path: /usr/ports
|
||||
register: ports
|
||||
|
||||
- block:
|
||||
|
||||
- name: COMMAND | Get ports
|
||||
command: portsnap fetch --interactive
|
||||
|
||||
- name: COMMAND | Extract ports
|
||||
command: portsnap extract
|
||||
no_log: true
|
||||
|
||||
when: not ports.stat.exists
|
||||
|
||||
- name: SHELL | Install ngrok
|
||||
shell: make install clean DISABLE_LICENSES=yes
|
||||
args:
|
||||
chdir: /usr/ports/security/ngrok
|
||||
creates: "{{ ngrok_path }}"
|
||||
|
||||
18
tests/includes/pre_common.yml
Normal file
18
tests/includes/pre_common.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
|
||||
- name: SHELL | Start ngrok
|
||||
shell: daemonize -l /tmp/ngrok.lock {{ ngrok_path }} http 8888 -bind-tls=false
|
||||
failed_when: false
|
||||
changed_when: ngrok.stderr.find("Can't lock the lock file") == -1
|
||||
register: ngrok
|
||||
|
||||
- name: WAIT_FOR | ngrok started
|
||||
wait_for:
|
||||
delay: 2
|
||||
port: 4040
|
||||
when: ngrok.changed
|
||||
|
||||
- name: SHELL | Get ngrok public address
|
||||
shell: curl 'http://127.0.0.1:4040/api/tunnels/command_line' | jq '.public_url' | grep -oE '[[:alnum:]]+\.ngrok\.io'
|
||||
register: ngrok
|
||||
changed_when: false
|
||||
@@ -4,22 +4,29 @@
|
||||
pre_tasks:
|
||||
- name: INCLUDE | Pre_tasks related to OS version
|
||||
include: "includes/pre_{{ ansible_distribution }}.yml"
|
||||
|
||||
- name: INCLUDE | Pre_tasks common
|
||||
include: "includes/pre_common.yml"
|
||||
|
||||
- name: FILE | Create an internal SSL dir
|
||||
file:
|
||||
path: "{{ int_ansible_ssl_dir }}"
|
||||
state: directory
|
||||
|
||||
- name: COPY | Deploy test certificate
|
||||
copy:
|
||||
src: "file/test.crt"
|
||||
dest: "{{ int_ansible_ssl_dir }}/test.crt"
|
||||
|
||||
- name: COPY | Deploy test key
|
||||
copy:
|
||||
src: "file/test.key"
|
||||
dest: "{{ int_ansible_ssl_dir }}/test.key"
|
||||
|
||||
- name: LINEINFILE | Add all hosts in /etc/hosts
|
||||
lineinfile:
|
||||
line: "127.0.2.1\t{% for s in nginx_sites %}{% if s.name is string %}{{ s.name }}{% else %}{% for n in s.name %}{{ n }} {% endfor %}{% endif %} {% if s.redirect_from is defined %}{% for rf in s.redirect_from %}{{ rf }} {% endfor %}{% endif %}{% endfor %}"
|
||||
regexp: '^127\.0\.2'
|
||||
line: "127.0.0.1\tlocalhost {% for s in nginx_sites %}{% if s.name is string %}{{ s.name }}{% else %}{% for n in s.name %}{{ n }} {% endfor %}{% endif %} {% if s.redirect_from is defined %}{% for rf in s.redirect_from %}{{ rf }} {% endfor %}{% endif %}{% endfor %}"
|
||||
regexp: '^127\.0\.0\.1'
|
||||
dest: "/etc/hosts"
|
||||
unsafe_writes: yes
|
||||
|
||||
@@ -122,7 +129,7 @@
|
||||
-----END CERTIFICATE-----
|
||||
nginx_custom_http:
|
||||
- 'add_header X-ansible 1;'
|
||||
- 'geoip_country /usr/share/GeoIP/GeoIP.dat;'
|
||||
- 'geoip_country {% if ansible_distribution == "Debian" %}/usr/share/GeoIP/GeoIP.dat{% else %}/usr/local/share/GeoIP/GeoIP.dat{% endif %};'
|
||||
- 'map $geoip_country_code $allowed_country {'
|
||||
- ' default yes;'
|
||||
- ' MA no;'
|
||||
@@ -236,6 +243,9 @@
|
||||
template: '_base'
|
||||
ssl_name: 'test-ssl.local'
|
||||
redirect_https: true
|
||||
redirect_from:
|
||||
- 'www.test-ssl-redirect-many.local'
|
||||
- 'www.test-ssl-redirect-many2.local'
|
||||
- name: 'test-ssl-proxy-protocol.local'
|
||||
proto: ['http', 'https']
|
||||
listen: [80, 20080]
|
||||
@@ -324,7 +334,17 @@
|
||||
status_code: 301
|
||||
follow_redirects: none
|
||||
with_items: "{{ nginx_sites }}"
|
||||
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent")
|
||||
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent") and (item.proto is not defined or 'https' not in item.proto)
|
||||
changed_when: false
|
||||
|
||||
- name: -- VERIFY REDIRECT HTTPS SITES --
|
||||
uri:
|
||||
url: "https://{{ item.redirect_from[0] }}:{{ item.listen_ssl[0] | default(443) }}/"
|
||||
status_code: 301
|
||||
follow_redirects: none
|
||||
validate_certs: no
|
||||
with_items: "{{ nginx_sites }}"
|
||||
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent") and item.proto is defined and 'https' in item.proto
|
||||
changed_when: false
|
||||
|
||||
# --------------------------------
|
||||
@@ -401,7 +421,7 @@
|
||||
failed_when: authbpc.content.find('BackupPC Server Status') == -1
|
||||
|
||||
# --------------------------------
|
||||
# Nagios (not avaiblable on Debian >= 9)
|
||||
# Nagios (not avaiblable on Debian >= 9 and not tested on FreeBSD)
|
||||
# --------------------------------
|
||||
- block:
|
||||
|
||||
@@ -425,29 +445,7 @@
|
||||
register: nagios_cgi
|
||||
failed_when: nagios_cgi.content.find('Nagios Event Summary') == -1
|
||||
|
||||
when: ansible_distribution_major_version | version_compare('9', 'lt')
|
||||
|
||||
|
||||
# --------------------------------
|
||||
# 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'
|
||||
when: ansible_distribution == 'Debian' and ansible_distribution_major_version | version_compare('9', 'lt')
|
||||
|
||||
# --------------------------------
|
||||
# SSL
|
||||
|
||||
@@ -5,3 +5,5 @@ nginx_etc_dir: '/usr/local/etc/nginx'
|
||||
# Specific sites
|
||||
nginx_nagios_root: '/usr/local/www/nagios'
|
||||
nginx_fcgiwrap_sock: '/var/run/fcgiwrap/fcgiwrap.sock'
|
||||
|
||||
nginx_acmesh_bin: '/usr/local/sbin/acme.sh'
|
||||
|
||||
@@ -32,11 +32,16 @@ nginx_dirs:
|
||||
- dir: "{{ nginx_helper_dir }}"
|
||||
mode: "0755"
|
||||
owner: "root"
|
||||
- dir: "{{ nginx_etc_dir }}/modules-available"
|
||||
mode: "0755"
|
||||
owner: "root"
|
||||
- dir: "{{ nginx_etc_dir }}/modules-enabled"
|
||||
mode: "0755"
|
||||
owner: "root"
|
||||
|
||||
nginx_templates_no_dir:
|
||||
- '_backuppc'
|
||||
- '_nagios3'
|
||||
- '_owncloud'
|
||||
- '_proxy'
|
||||
|
||||
nginx_servers_default_headers:
|
||||
|
||||
Reference in New Issue
Block a user