mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb704da8d8 | ||
|
|
64a9ab7c68 | ||
|
|
c4ee6eb1a2 | ||
|
|
8789bd2c9c | ||
|
|
a2e6e98436 | ||
|
|
fc44b704cf | ||
|
|
cf662acdd7 | ||
|
|
34c8d1926f | ||
|
|
634d88874f | ||
|
|
5e254331c4 |
@@ -40,6 +40,7 @@ FreeBSD:
|
|||||||
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
|
- `nginx_resolver`: list of DNS resolver (default: OpenDNS)
|
||||||
- `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 Configuration
|
### Nginx Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ nginx_error_log_level: 'warn' # http://nginx.org/en/docs/ngx_core_module.html#er
|
|||||||
nginx_auto_config_httpv2: true
|
nginx_auto_config_httpv2: true
|
||||||
nginx_default_vhost: null
|
nginx_default_vhost: null
|
||||||
nginx_default_vhost_ssl: null
|
nginx_default_vhost_ssl: null
|
||||||
|
nginx_fastcgi_fix_realpath: true
|
||||||
|
|
||||||
#
|
#
|
||||||
# Nginx directories
|
# Nginx directories
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ Common
|
|||||||
|
|
||||||
- `name`: (M) Domain or list of domain used.
|
- `name`: (M) Domain or list of domain used.
|
||||||
- `template`: (D) template used to create vhost. Optional if you set `delete` to true or using `redirect_tor`.
|
- `template`: (D) template used to create vhost. Optional if you set `delete` to true or using `redirect_tor`.
|
||||||
- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword).
|
- `filename`: (O) Specify filename in /etc/nginx/sites-*. Do NOT specify default (reserved keyword). It will be used for log filenames and directories creation.
|
||||||
- `enable`: (O) Enable the vhost (default is true)
|
- `state`: (O) Vhost status. Can be "present" (default), "absent" and "disabled".
|
||||||
- `delete`: (O) Delete the vhost (default is false)
|
|
||||||
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
- `redirect_from`: (O) Domain list to redirect to the first `name`. You can use this key to redirect non-www to www
|
||||||
- `redirect_to`: (O) Redirect all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
- `redirect_to`: (O) Redirect all requests to this domain. Please set scheme (http:// or https:// or $sheme).
|
||||||
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
|
- `headers`: (O) Set additionals header as key/value list. You can append "always" to the value. Show [nginx doc](http://nginx.org/en/docs/http/ngx_http_headers_module.html).
|
||||||
|
|||||||
@@ -19,3 +19,16 @@
|
|||||||
dest="{{ nginx_etc_dir }}/conf.d/custom.conf"
|
dest="{{ nginx_etc_dir }}/conf.d/custom.conf"
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: LINEINFILE | Fix path
|
||||||
|
lineinfile: >
|
||||||
|
regexp='{{ item.0.regexp }}'
|
||||||
|
line='{{ item.0.line }}'
|
||||||
|
dest='{{ item.1 }}'
|
||||||
|
with_nested:
|
||||||
|
-
|
||||||
|
- regexp: '^fastcgi_param SCRIPT_FILENAME'
|
||||||
|
line: 'fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;'
|
||||||
|
- regexp: '^fastcgi_param DOCUMENT_ROOT'
|
||||||
|
line: 'fastcgi_param DOCUMENT_ROOT $realpath_root;'
|
||||||
|
- [ '/etc/nginx/fastcgi_params', '/etc/nginx/fastcgi.conf' ]
|
||||||
|
when: nginx_fastcgi_fix_realpath
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- name: SET_FACT | Backward compatibility with old version of this role
|
||||||
|
set_fact: >
|
||||||
|
nginx_php56: true
|
||||||
|
when: nginx_php is defined and nginx_php
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
||||||
template: >
|
template: >
|
||||||
src=etc/nginx/upstream/php.conf.j2
|
src=etc/nginx/upstream/php.conf.j2
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
- name: FILE | Create root public folders (foreach nginx_vhosts)
|
||||||
file: >
|
file: >
|
||||||
path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public
|
path={{ nginx_root }}/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}/public
|
||||||
state=directory
|
state=directory
|
||||||
owner={{ item.owner | default(nginx_user) }}
|
owner={{ item.owner | default(nginx_user) }}
|
||||||
group={{ item.group | default(nginx_user) }}
|
group={{ item.group | default(nginx_user) }}
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
when: >
|
when: >
|
||||||
item.root is not defined and
|
item.root is not defined and
|
||||||
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
(item.template is defined and item.template not in nginx_templates_no_dir) and
|
||||||
(item.delete is not defined or not item.delete) and
|
(item.state is not defined or not item.state != 'absent') and
|
||||||
item.redirect_to is not defined
|
item.redirect_to is not defined
|
||||||
|
|
||||||
- name: TEMPLATE | Create vhosts
|
- name: TEMPLATE | Create vhosts
|
||||||
@@ -45,13 +45,13 @@
|
|||||||
dest={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
dest={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }}
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.delete is not defined or not item.delete
|
when: item.state is not defined or item.state != 'absent'
|
||||||
|
|
||||||
- name: FILE | Delete vhosts
|
- name: FILE | Delete vhosts
|
||||||
file: path={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
file: path={{ nginx_etc_dir }}/sites-available/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: item.delete is defined and item.delete
|
when: item.state is defined and item.state == 'absent'
|
||||||
|
|
||||||
- name: FILE | Enable vhosts
|
- name: FILE | Enable vhosts
|
||||||
file: >
|
file: >
|
||||||
@@ -61,15 +61,13 @@
|
|||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: >
|
when: >
|
||||||
((item.enable is not defined) or
|
item.state is not defined or item.state == 'present'
|
||||||
(item.enable is defined and item.enable)) and
|
|
||||||
(item.delete is not defined or not item.delete)
|
|
||||||
|
|
||||||
- name: FILE | Disable vhosts
|
- name: FILE | Disable vhosts
|
||||||
file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.filename | default(item.name if item.name is string else item.name[0]) }} state=absent
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
notify: ['reload nginx', 'restart nginx freebsd']
|
notify: ['reload nginx', 'restart nginx freebsd']
|
||||||
when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete)
|
when: item.state is defined and item.state == 'disabled'
|
||||||
|
|
||||||
- name: FILE | Delete default vhost when explicitely defined
|
- name: FILE | Delete default vhost when explicitely defined
|
||||||
file: >
|
file: >
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% set __proto = item.proto | default(['http']) %}
|
{% set __proto = item.proto | default(['http']) %}
|
||||||
{% set __main_name = item.name if item.name is string else item.name[0] %}
|
{% set __main_name = item.filename | default(item.name if item.name is string else item.name[0]) %}
|
||||||
{% set __listen = item.listen | default(['80']) %}
|
{% set __listen = item.listen | default(['80']) %}
|
||||||
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
{% set __listen_ssl = item.listen_ssl | default(['443']) %}
|
||||||
{% set __location = item.location | default({}) %}
|
{% set __location = item.location | default({}) %}
|
||||||
@@ -38,7 +38,7 @@ server {
|
|||||||
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
include {{ nginx_helper_dir + '/ssl-' + item.ssl_template | default('strong') }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %};
|
server_name {% if item.name is string %}{{ item.name }}{% else %}{{ "\n\t\t" }}{{ item.name | join("\n\t\t") }}{% endif %};
|
||||||
{% block root %}
|
{% block root %}
|
||||||
{% if item.root is defined %}
|
{% if item.root is defined %}
|
||||||
root {{ item.root }};
|
root {{ item.root }};
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{% extends "_base.j2" %}
|
{% extends "_base.j2" %}
|
||||||
|
|
||||||
{% macro phpv(version) %}
|
{% macro phpv(version) %}
|
||||||
{% if version == 56 %}
|
{% if version == 56 or version == "5.6" %}
|
||||||
{{ nginx_upstream_php56 -}}
|
{{ nginx_upstream_php56 -}}
|
||||||
{% elif version == 70 %}
|
{% elif version == 70 or version == "7.0" %}
|
||||||
{{ nginx_upstream_php70 -}}
|
{{ nginx_upstream_php70 -}}
|
||||||
{% else %}
|
{% else %}
|
||||||
{# Hack... define another upstream #}
|
{# Hack... define another upstream #}
|
||||||
|
|||||||
@@ -3,3 +3,9 @@
|
|||||||
{% block template_try_files %}
|
{% block template_try_files %}
|
||||||
try_files $uri $uri/ /index.php?$args;
|
try_files $uri $uri/ /index.php?$args;
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block template_custom_location %}
|
||||||
|
location ~* /(?:uploads|files)/.*\.php$ {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
nginx_custom_http:
|
nginx_custom_http:
|
||||||
- 'add_header X-ansible 1;'
|
- 'add_header X-ansible 1;'
|
||||||
nginx_default_vhost: 'test.local'
|
nginx_default_vhost: 'first-test'
|
||||||
nginx_default_vhost_ssl: 'test-ssl-predeployed.local'
|
nginx_default_vhost_ssl: 'test-ssl-predeployed.local'
|
||||||
nginx_vhosts:
|
nginx_vhosts:
|
||||||
- name:
|
- name:
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
'X-Frame-Options': 'deny always'
|
'X-Frame-Options': 'deny always'
|
||||||
'X-ansible-default': '1'
|
'X-ansible-default': '1'
|
||||||
manage_local_content: false
|
manage_local_content: false
|
||||||
use_error_log: false
|
use_error_log: true
|
||||||
more:
|
more:
|
||||||
- 'autoindex off;'
|
- 'autoindex off;'
|
||||||
location:
|
location:
|
||||||
@@ -165,7 +165,7 @@
|
|||||||
headers:
|
headers:
|
||||||
'X-proxyfied': '1'
|
'X-proxyfied': '1'
|
||||||
- name: 'deleted.local'
|
- name: 'deleted.local'
|
||||||
delete: true
|
state: 'absent'
|
||||||
- name: 'redirect-to.local'
|
- name: 'redirect-to.local'
|
||||||
redirect_to: 'http://test.local'
|
redirect_to: 'http://test.local'
|
||||||
- name: 'backuppc.local'
|
- name: 'backuppc.local'
|
||||||
@@ -209,7 +209,7 @@
|
|||||||
with_items: ['test-php.local', 'test-php-index.local']
|
with_items: ['test-php.local', 'test-php-index.local']
|
||||||
- name: -- Add HTML file --
|
- name: -- Add HTML file --
|
||||||
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
|
copy: dest="{{ item }}/index.html" content="Index HTML test OK\n"
|
||||||
with_items: ['{{ nginx_root }}/test.local/public', '/var/tmp', '{{ nginx_root }}/test-htpasswd-all.local/public', '{{ nginx_root }}/test-ssl.local/public', '{{ nginx_root }}/test-ssl-predeployed.local/public']
|
with_items: ['{{ nginx_root }}/first-test/public', '/var/tmp', '{{ nginx_root }}/test-htpasswd-all.local/public', '{{ nginx_root }}/test-ssl.local/public', '{{ nginx_root }}/test-ssl-predeployed.local/public']
|
||||||
- name: -- Create directory --
|
- name: -- Create directory --
|
||||||
file: path={{ nginx_root }}/test-htpasswd.local/public/hello state=directory
|
file: path={{ nginx_root }}/test-htpasswd.local/public/hello state=directory
|
||||||
- name: -- Add HTML file hello --
|
- name: -- Add HTML file hello --
|
||||||
@@ -220,7 +220,7 @@
|
|||||||
- name: -- VERIFY VHOSTS --
|
- name: -- VERIFY VHOSTS --
|
||||||
command: "curl -H 'Host: {{ item.name if item.name is string else item.name[0] }}' http://127.0.0.1{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
|
command: "curl -H 'Host: {{ item.name if item.name is string else item.name[0] }}' http://127.0.0.1{% if item.listen is defined %}:{{ item.listen[0] }}{% endif %}/"
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
when: item.delete is undefined or not item.delete
|
when: item.state is undefined or item.state != "absent"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
- name: -- VERIFY FORBIDDEN --
|
- name: -- VERIFY FORBIDDEN --
|
||||||
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
|
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
|
||||||
@@ -230,7 +230,7 @@
|
|||||||
- name: -- VERIFY REDIRECT VHOSTS --
|
- name: -- VERIFY REDIRECT VHOSTS --
|
||||||
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
|
command: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/"
|
||||||
with_items: "{{ nginx_vhosts }}"
|
with_items: "{{ nginx_vhosts }}"
|
||||||
when: item.redirect_from is defined and (item.delete is undefined or not item.delete)
|
when: item.redirect_from is defined and (item.state is undefined or item.state != "absent")
|
||||||
changed_when: false
|
changed_when: false
|
||||||
register: r
|
register: r
|
||||||
failed_when: r.stdout.find('301 Moved Permanently') == -1
|
failed_when: r.stdout.find('301 Moved Permanently') == -1
|
||||||
|
|||||||
Reference in New Issue
Block a user