mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-02-28 09:22:10 +07:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a612a55b9 | ||
|
|
1280a441ee | ||
|
|
21edb6b584 | ||
|
|
c524b97b0f | ||
|
|
993310641a | ||
|
|
f5885c5c55 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
*.swp
|
||||
*.retry
|
||||
*.pyc
|
||||
/tests/HanXHX.php
|
||||
|
||||
@@ -26,6 +26,7 @@ before_install:
|
||||
|
||||
install:
|
||||
- pip install "$ANSIBLE_VERSION"
|
||||
- ansible-galaxy install -p ./tests HanXHX.php,master
|
||||
|
||||
script:
|
||||
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
|
||||
|
||||
10
README.md
10
README.md
@@ -105,6 +105,16 @@ Dependencies
|
||||
|
||||
None
|
||||
|
||||
|
||||
If you need to dev this role locally
|
||||
------------------------------------
|
||||
|
||||
Before use vagrant, run once:
|
||||
|
||||
```
|
||||
ansible-galaxy install -p ./tests/ HanXHX.php,master
|
||||
```
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
|
||||
@@ -51,3 +51,4 @@
|
||||
creates: "{{ nginx_acmesh_dir }}"
|
||||
|
||||
when: not acme.stat.exists
|
||||
|
||||
|
||||
@@ -1,18 +1,40 @@
|
||||
---
|
||||
|
||||
- block:
|
||||
|
||||
- name: SET_FACT | temp
|
||||
set_fact:
|
||||
tmp_fpm_pool: |
|
||||
[
|
||||
{% for p in ansible_local.hanxhx_php.fpm_pool %}
|
||||
{
|
||||
"upstream_name": "{{ p.name }}",
|
||||
"sockets": [{
|
||||
{% if p.listen.startswith('/') %}
|
||||
"unix": "{{ p.listen }}"
|
||||
{% else %}
|
||||
{% set host = p.listen.split(":")[0] %}
|
||||
{% set port = p.listen.split(":")[1] %}
|
||||
"host": "{{ host }}",
|
||||
"port": "{{ port }}"
|
||||
{% endif %}
|
||||
}]
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
|
||||
- name: SET_FACT | new php
|
||||
set_fact:
|
||||
nginx_php: "{{ nginx_php + tmp_fpm_pool }}"
|
||||
|
||||
when: ansible_local.hanxhx_php.fpm_pool is defined
|
||||
|
||||
- name: TEMPLATE | Deploy PHP upstream to Nginx
|
||||
template:
|
||||
src: "etc/nginx/conf.d/php.conf.j2"
|
||||
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
|
||||
when: nginx_php | length > 0
|
||||
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
|
||||
template:
|
||||
src: "etc/nginx/conf.d/_upstream.conf.j2"
|
||||
|
||||
@@ -14,7 +14,18 @@ upstream {{ php.upstream_name | default((php.version | php_default_upstream_name
|
||||
server unix:{{ php.version | php_default_upstream_socket }} weight=1;
|
||||
{% 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
|
||||
|
||||
@@ -106,7 +106,7 @@ server {
|
||||
{% block template_headers %}
|
||||
# --> Custom headers
|
||||
{% for key, value in __headers.iteritems() %}
|
||||
add_header {{ key }} "{{ value }}";
|
||||
add_header {{ key }} "{{ value | regex_replace('\s+always$', '') }}"{% if value | regex_search('\s+always$') %} always{% endif %};
|
||||
{% endfor %}
|
||||
# <-- Custom headers
|
||||
{% endblock %}
|
||||
@@ -140,7 +140,7 @@ server {
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ {
|
||||
location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg|(o|t)tf|woff2?|eot)$ {
|
||||
expires 30d;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
28
templates/etc/nginx/sites-available/_symfony.j2
Normal file
28
templates/etc/nginx/sites-available/_symfony.j2
Normal file
@@ -0,0 +1,28 @@
|
||||
{% 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(/|$) {
|
||||
# {{ php_info }}
|
||||
fastcgi_pass {{ php_upstream }};
|
||||
fastcgi_index index.php;
|
||||
{% if item.upstream_params is defined and item.upstream_params is iterable %}
|
||||
{% for param in item.upstream_params %}
|
||||
{{ param }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
include fastcgi.conf;
|
||||
internal;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
return 404;
|
||||
}
|
||||
{% endblock %}
|
||||
@@ -78,3 +78,24 @@
|
||||
- name: SET_FACT | ngrok_path
|
||||
set_fact:
|
||||
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: "{{ nginx_php.0.version }}"
|
||||
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'
|
||||
|
||||
@@ -213,8 +213,10 @@
|
||||
use_access_log: true
|
||||
- name: 'test-php-index.local'
|
||||
template: '_php_index'
|
||||
php_upstream: 'hx_unix'
|
||||
- name: 'test-php-index2.local'
|
||||
template: '_php_index2'
|
||||
php_upstream: 'hx_ip'
|
||||
- name: 'test-proxy.local'
|
||||
listen:
|
||||
- 8080
|
||||
|
||||
@@ -46,6 +46,6 @@ nginx_templates_no_dir:
|
||||
nginx_servers_default_headers:
|
||||
'X-Frame-Options': 'DENY 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"
|
||||
|
||||
Reference in New Issue
Block a user