Skip to content
Browse files

nginx: new nginx::site::static to create static sites

  • Loading branch information...
1 parent dc0638f commit 9b716974b7e3d56ec612169e1bbb6b6743f67a03 @daks committed
Showing with 80 additions and 1 deletion.
  1. +29 −1 nginx/README
  2. +33 −0 nginx/manifests/site/static.pp
  3. +18 −0 nginx/templates/static.erb
View
30 nginx/README
@@ -53,7 +53,35 @@ nginx::site::redirect
enable this vhost?
-nginx::site::proxy
+nginx::site::static
+
+ creates a virtualhost to serve static files
+
+ parameters:
+
+ server_name (mandatory):
+ the virtualhost name
+
+ server_aliases (optional):
+ an array with alternative server names
+
+ port (optional, default: 80):
+ its port
+
+ root_dir (mandatory):
+ the root directory
+
+ index_files (optional, default: 'index.html index.htm'):
+ specify files to be used as an index to the directory served
+
+ default_vhost (optional, default: false):
+ is this vhost the default one?
+
+ enabled (optional, default: true):
+ enable this vhost?
+
+
+ginx::site::proxy
creates a virtualhost using nginx as a proxy
View
33 nginx/manifests/site/static.pp
@@ -0,0 +1,33 @@
+
+define nginx::site::static($server_name,
+ $server_aliases=[],
+ $port='80',
+ $root_dir,
+ $index_files='index.html index.htm',
+ $default_vhost=false,
+ $enabled=true) {
+
+ include nginx::package
+
+ $define_port = $default_vhost ?{
+ true => "${port} default",
+ default => "${port}",
+ }
+
+ $src_filename = "/etc/nginx/sites-available/${name}"
+ $dst_filename = "/etc/nginx/sites-enabled/${name}"
+
+ file { "${src_filename}":
+ content => template("nginx/static.erb")
+ }
+
+ $ensure = $enabled ? {
+ true => "link",
+ default => "absent",
+ }
+
+ file { "${dst_filename}":
+ ensure => "${ensure}",
+ target => "${src_filename}",
+ }
+}
View
18 nginx/templates/static.erb
@@ -0,0 +1,18 @@
+# /etc/nginx/sites-available/<%= name %>
+#
+# file managed by Puppet
+# do not make any manual change here as it will be overwritten
+#
+# module nginx
+
+server {
+ listen <%= define_port %>;
+ server_name <%= server_name %><% server_aliases.each do |val| -%> <%= val %><% end -%>;
+
+ access_log /var/log/nginx/<%= server_name %>.access.log;
+ error_log /var/log/nginx/<%= server_name %>.error.log;
+
+ root <%= root_dir %>;
+ index <%= index_files %>;
+}
+

0 comments on commit 9b71697

Please sign in to comment.
Something went wrong with that request. Please try again.