From 97c3d2e169394db008b8991372ec13b91e37bb61 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Mon, 2 Nov 2015 16:30:46 +0100 Subject: [PATCH] Fix and improve tests/vhosts + php_index vhost --- README.md | 6 +++-- templates/etc/nginx/sites-available/_base.j2 | 2 +- .../etc/nginx/sites-available/_php_index.j2 | 24 +++++++++++++++++++ tests/test.yml | 14 +++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 templates/etc/nginx/sites-available/_php_index.j2 diff --git a/README.md b/README.md index 0877c70..eed5006 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,12 @@ You can see many examples in: [tests/test.yml](tests/test.yml). #### Templates - `base`: static template - - `php`: PHP base template. Can work with many frameworks/tools. - - `wordpress` - `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` + - `wordpress` Templates works as parent-child. diff --git a/templates/etc/nginx/sites-available/_base.j2 b/templates/etc/nginx/sites-available/_base.j2 index 1c3cf87..e709df4 100644 --- a/templates/etc/nginx/sites-available/_base.j2 +++ b/templates/etc/nginx/sites-available/_base.j2 @@ -16,7 +16,7 @@ server { {% if item.root is defined %} root {{ item.root }}; {% else %} - root {{ nginx_root }}/{{ item.name[0] }}/public; + root {{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public; {% endif %} {% block template_index %} index {{ item.index | default('index.html index.htm') }}; diff --git a/templates/etc/nginx/sites-available/_php_index.j2 b/templates/etc/nginx/sites-available/_php_index.j2 new file mode 100644 index 0000000..e56cb34 --- /dev/null +++ b/templates/etc/nginx/sites-available/_php_index.j2 @@ -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 %} diff --git a/tests/test.yml b/tests/test.yml index d84ad60..c4ddfdb 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -36,6 +36,8 @@ redirect_from: - 'www.test-php.local' template: '_php' + - name: 'test-php-index.local' + template: '_php_index' - name: 'test-proxy.local' listen: - 8080 @@ -48,16 +50,24 @@ - ../../ post_tasks: - name: -- Add PHP file -- - copy: dest="{{ nginx_root }}/test-php.local/public/index.php" content="