Permalink
Browse files

redirect

  • Loading branch information...
1 parent 388754f commit f87ae3e9436a6acfa901c419928c6aa4e9e74f6d @melezhik committed May 17, 2012
View
@@ -80,6 +80,25 @@ To install nginx site config with `expires` parameter:
expires '+30d'
end
+To install nginx site config for http/https virtual hosts with hostname bar.site.x, with all http traffic get redirected to https host:
+
+ nginx_fastcgi '/tmp/foo.site.conf' do
+ servers [
+ {
+ :ip => '127.0.0.1',
+ :server_name => 'bar.site.x',
+ :redirect => 'https'
+ },
+ {
+ :ip => '127.0.0.1',
+ :server_name => 'bar.site.x',
+ :ssl => true,
+ :ssl_include_path => 'nginx_ssl_settings.conf'
+
+ }
+ ]
+ end
+
Features
===
@@ -0,0 +1,31 @@
+Feature: nginx-fastcgi should be able to install ssl enabled nginx site config
+
+Backgound: delete old configs
+ Given I run 'rm -rf /tmp/foo.site.conf'
+ Then a file named '/tmp/foo.site.conf' should not exist
+
+Scenario: install nginx ssl site config
+ And I have chef recipe:
+ """
+ nginx_fastcgi '/tmp/foo.site.conf' do
+ servers [
+ {
+ :ip => '127.0.0.1',
+ :server_name => 'bar.site.x',
+ :redirect => 'https'
+ },
+ {
+ :ip => '127.0.0.1',
+ :server_name => 'bar.site.x',
+ :ssl => true,
+ :ssl_include_path => 'nginx_ssl_settings.conf'
+
+ }
+ ]
+ end
+ """
+ When I run chef recipe on my node
+ Then a file named '/tmp/foo.site.conf' should exist
+ And a file named '/tmp/foo.site.conf' should contain 'rewrite \^ https://\$server_name\$request_uri\? permanent'
+
+
@@ -13,6 +13,7 @@ server {
<%- end %>
expires <%= @expires %>;
+ <%- if s[:redirect].nil? || s[:redirect].empty? %>
location / {
include fastcgi_params;
<%- if s[:ssl_on] == true %>
@@ -34,6 +35,9 @@ server {
expires <%= st[:expires] || '-1s' %>;
}
<%- end %>
+ <%- else %>
+ rewrite ^ <%= s[:redirect] %>://$server_name$request_uri? permanent;
+ <%- end %>
}
<%- end %>

0 comments on commit f87ae3e

Please sign in to comment.