Fix and improve tests/vhosts + php_index vhost

pull/14/head 1.0.6
Emilien Mantel 2015-11-02 16:30:46 +01:00
parent c2644d4e5d
commit 97c3d2e169
4 changed files with 41 additions and 5 deletions

View File

@ -70,10 +70,12 @@ You can see many examples in: [tests/test.yml](tests/test.yml).
#### Templates #### Templates
- `base`: static template - `base`: static template
- `php`: PHP base template. Can work with many frameworks/tools.
- `wordpress`
- `dokuwiki` - `dokuwiki`
- `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
- `proxy` - `proxy`
- `wordpress`
Templates works as parent-child. Templates works as parent-child.

View File

@ -16,7 +16,7 @@ server {
{% if item.root is defined %} {% if item.root is defined %}
root {{ item.root }}; root {{ item.root }};
{% else %} {% else %}
root {{ nginx_root }}/{{ item.name[0] }}/public; root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public;
{% endif %} {% endif %}
{% block template_index %} {% block template_index %}
index {{ item.index | default('index.html index.htm') }}; index {{ item.index | default('index.html index.htm') }};

View File

@ -0,0 +1,24 @@
{% extends "_php.j2" %}
{% block template_upstream_location %}
location = /index.php {
fastcgi_pass php;
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 %}
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
include fastcgi_params;
{% else %}
include fastcgi.conf;
{% endif %}
}
{% endblock %}
{% block template_custom_location %}
location ~ \.(php\d?|phtml)$ {
return 403;
}
{% endblock %}

View File

@ -36,6 +36,8 @@
redirect_from: redirect_from:
- 'www.test-php.local' - 'www.test-php.local'
template: '_php' template: '_php'
- name: 'test-php-index.local'
template: '_php_index'
- name: 'test-proxy.local' - name: 'test-proxy.local'
listen: listen:
- 8080 - 8080
@ -48,16 +50,24 @@
- ../../ - ../../
post_tasks: post_tasks:
- name: -- Add PHP file -- - name: -- Add PHP file --
copy: dest="{{ nginx_root }}/test-php.local/public/index.php" content="<?php phpinfo();" copy: dest="{{ nginx_root }}/{{ item }}/public/index.php" content="<?php phpinfo();"
with_items: ['test-php.local', 'test-php-index.local']
- name: -- Add HTML file -- - name: -- Add HTML file --
copy: dest="{{ nginx_root }}/test.local/public/index.html" content="Index HTML test OK\n" copy: dest="{{ nginx_root }}/test.local/public/index.html" content="Index HTML test OK\n"
- name: -- VERIFY VHOSTS -- - name: -- VERIFY VHOSTS --
shell: "curl -H 'Host: {{ item.name[0] }}' http://127.0.0.1{% if item.listen is defined and item.listen is iterable %}:{{ item.listen[0] }}{% endif %}/" shell: "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.delete is undefined or not item.delete
changed_when: false changed_when: false
- name: -- VERIFY FORBIDDEN --
command: "curl -H 'Host: test-php-index.local' http://127.0.0.1/phpinfo.php"
register: f
failed_when: f.stdout.find('403 Forbidden') == -1
changed_when: false
- name: -- VERIFY REDIRECT VHOSTS -- - name: -- VERIFY REDIRECT VHOSTS --
shell: "curl -H 'Host: {{ item.redirect_from[0] }}' http://127.0.0.1/" shell: "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.delete is undefined or not item.delete)
changed_when: false changed_when: false
register: r
failed_when: r.stdout.find('301 Moved Permanently') == -1