├── .gitignore ├── .kitchen.yml ├── Berksfile ├── Berksfile.lock ├── README.md ├── attributes └── default.rb ├── metadata.rb ├── providers └── site.rb ├── recipes └── default.rb ├── resources └── site.rb ├── templates └── default │ ├── DEFAULT.erb │ ├── nginx.conf.erb │ └── site.conf.erb └── test ├── integration ├── default │ └── serverspec │ │ ├── localhost │ │ └── nginx_spec.rb │ │ └── spec_helper.rb └── passenger4 │ └── serverspec │ ├── localhost │ └── nginx_spec.rb │ └── spec_helper.rb └── test-cookbook ├── metadata.rb ├── recipes └── default.rb └── templates └── default ├── config.ru.erb ├── index.html.erb └── maintenance.html.erb /.gitignore: -------------------------------------------------------------------------------- 1 | .kitchen/ 2 | .bundle 3 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | require_chef_omnibus: true 5 | 6 | provisioner: chef_zero 7 | 8 | platforms: 9 | - name: ubuntu-12.04 10 | driver_config: 11 | image: ubuntu-upstart 12 | disable_upstart: false 13 | run_command: /sbin/init 14 | 15 | suites: 16 | - name: default 17 | run_list: 18 | - "recipe[nginx_passenger]" 19 | - "recipe[nginx_passenger-test]" 20 | attributes: 21 | nginx_passenger: 22 | sites_dir: "/etc/nginx/sites" 23 | log_dir: "/var/log/nginx-sites" 24 | catch_default: true 25 | - name: passenger4 26 | run_list: 27 | - "recipe[nginx_passenger]" 28 | - "recipe[nginx_passenger-test]" 29 | attributes: 30 | nginx_passenger: 31 | use_passenger_4: true 32 | sites_dir: "/etc/nginx/sites" 33 | log_dir: "/var/log/nginx-sites" 34 | catch_default: true -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source "https://api.berkshelf.com" 2 | 3 | metadata 4 | cookbook "nginx_passenger-test", path: "./test/test-cookbook" 5 | -------------------------------------------------------------------------------- /Berksfile.lock: -------------------------------------------------------------------------------- 1 | DEPENDENCIES 2 | nginx_passenger 3 | path: . 4 | metadata: true 5 | nginx_passenger-test 6 | path: test/test-cookbook 7 | 8 | GRAPH 9 | apt (2.4.0) 10 | nginx_passenger (0.5.7) 11 | apt (>= 0.0.0) 12 | ssl_certificate (>= 0.0.0) 13 | nginx_passenger-test (0.0.1) 14 | nginx_passenger (>= 0.0.0) 15 | ssl_certificate (1.3.0) 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | _ ______ 3 | (_) | ___ \ 4 | _ __ __ _ _ _ __ __ _| |_/ /_ _ ___ ___ ___ _ __ __ _ ___ _ __ 5 | | '_ \ / _` | | '_ \\ \/ / __/ _` / __/ __|/ _ \ '_ \ / _` |/ _ \ '__| 6 | | | | | (_| | | | | |> <| | | (_| \__ \__ \ __/ | | | (_| | __/ | 7 | |_| |_|\__, |_|_| |_/_/\_\_| \__,_|___/___/\___|_| |_|\__, |\___|_| 8 | __/ | __/ | 9 | |___/ |___/ 10 | --- 11 | 12 | This cookbook installs nginx and [Passenger](https://www.phusionpassenger.com/) 13 | using packages compiled by Phusion. If you want to do extensive nginx 14 | configuration, you may want to use the Opscode 15 | [nginx cookbook](https://github.com/opscode-cookbooks/nginx) instead. 16 | 17 | Currently the cookbook is only written for Ubuntu, since it assumes apt for 18 | package install. 19 | 20 | The default recipe adds the Phusion repository and installs the passenger and 21 | nginx packages. 22 | 23 | # Configuration Attributes 24 | 25 | * __use\_passenger\_4:__ If true, use Phusion's Passenger 4 repo rather than 26 | the main one (which is now Passenger 5). Default false. 27 | * __sites\_dir:__ Directory in which to write our virtualhost files. Defaults 28 | to `/etc/nginx/sites-enabled`. 29 | * __nginx\_workers:__ NGINX worker count. Defaults to 4. 30 | * __nginx\_connections:__ NGINX worker connection count. Defaults to 768. 31 | * __catch\_default`:__ If true, add an empty virtualhost file that catches all 32 | requests for hosts other than the ones explicitly registered in virtualhost 33 | files. Defaults to false. 34 | * __log\_dir:__ Directory for nginx and site log files. Defaults to `/var/log/nginx` 35 | * __certs\_dir:__ Directory for cert files. Defaults to `/etc/nginx/certs` 36 | * __ruby:__ Default Ruby interpreter. Defaults to `/usr/bin/ruby` 37 | * __max\_pool\_size`:__ Max number of passenger instances. Defaults to 8. 38 | * __max\_instances\_per\_app:__ Max number of passenger instances for a single app. Defaults to 0 (unlimited). 39 | * __min\_instances:__ Passenger config for default minimum instances of all apps. Defaults to 2. 40 | * __pool\_idle\_time:__ Max number of seconds a Passenger process may be idle. Defaults to 300. 41 | * __max\_requests:__ Max number of requests a Passenger process will handle. Defaults to 0. 42 | * __cert\_databag:__ What databag should we look for SSL certs in? Defaults to `ssl_certs` 43 | * __redirect\_to\_https:__ If a site supports https, should we redirect http 44 | requests there? Defaults to true. 45 | * __site\_min\_instances:__ Passenger config for minimum instances of each app. Overrides default `min_instances`. Defaults to 2. 46 | * __site\_max\_body\_size:__ Maximum body size for uploads. Defaults to `8M` 47 | * __keep\_env\_path:__ Tell nginx to pass the PATH environment variable through. Defaults to `true` 48 | * __default\_log\_format:__ What logging format should be used? Defaults to "combined". 49 | Also available is `combined_timing`, which adds request time and upstream response time. 50 | * __maintenance\_page:__ Default path to a maintenance page. Defaults to `nil` 51 | * __maintenance\_check:__ Default path to a maintenance check. Defaults to `nil` 52 | 53 | ## `nginx_passenger_site` 54 | 55 | The `nginx_passenger_site` resource is used to add a Passenger-enabled site 56 | to nginx. 57 | 58 | For instance: 59 | 60 | nginx_passenger_site "ewr" do 61 | action :create 62 | dir "/web/ewr/current" 63 | server "ewr.is" 64 | end 65 | 66 | That call would create an nginx config file at `/etc/nginx/sites-enabled/ewr` 67 | pointing to an app installed at `/web/ewr/current`. Because it's Passenger, 68 | the nginx root is actually set to `/web/ewr/current/public`. 69 | 70 | There are several other attributes that can be set on the resource: 71 | 72 | * __name:__ The site key. "ewr" in the example above. 73 | * __dir:__ The base directory for the application. 74 | * __server:__ The nginx `server_name` 75 | * __rails_env:__ Set the Passenger `rails_env` setting 76 | * __cert:__ Key that specifies an SSL certificate that should be downloaded 77 | and installed for the app. Uses a databag specified in 78 | `node.nginx_passenger.cert_databag`. 79 | * __generate_cert:__ If you do not have a certificate but want your site to be served over https, setting this to true will cause the a key and cert to be automatically generated for you. Note that this certificate will be self signed and should probably not be used in production environments! You can set `node.nginx_passenger.cert_authority` if you wish to change the certificate authority shown on the certificate, which ships as 'Self Signed'. 80 | * __http:__ Should HTTP be supported? If no cert is provided, the answer 81 | will be yes, regardless of the value of this flag. If a cert is provided 82 | (and HTTPS is therefore enabled), this setting determines whether the 83 | app should also be served up over HTTP. If not, you can optionally have 84 | HTTP access redirect to HTTPS based on the value of 85 | `node.nginx_passenger.redirect_to_https`. 86 | * __template:__ If you would like to specify custom nginx / Passenger 87 | configuration, you can specify its name here. By default, the resource 88 | will use a stock config that is included. 89 | * __min_instances:__ Passenger's `passenger_min_instances` setting. By default, 90 | set to the value of `node.nginx_passenger.site_min_instances`, which ships as 91 | to 2. 92 | * __max\_body\_size:__ Nginx `client_max_body_size` setting. Defaults to 93 | `node.nginx_passenger.site_max_body_size`, which ships as '8M' (8 megabytes). 94 | 95 | If `site` resource specifies a `maintenance_page`, traffic will be redirected 96 | there if a given maintenance check file is present. By default, we look for 97 | `(dir)/IN_MAINTENANCE_MODE`, but a custom file can be specified with 98 | the `maintenance_check` attribute. 99 | 100 | ## Who 101 | 102 | This cookbook was written by [Eric Richardson](http://ewr.is), loosely based on 103 | practices developed putting together cookbooks for [Emcien](http://emcien.com). 104 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | default.nginx_passenger.use_passenger_4 = false 2 | 3 | default.nginx_passenger.sites_dir = "/etc/nginx/sites-enabled" 4 | default.nginx_passenger.nginx_workers = 4 5 | default.nginx_passenger.nginx_connections = 768 6 | default.nginx_passenger.catch_default = false 7 | 8 | default.nginx_passenger.log_dir = "/var/log/nginx" 9 | default.nginx_passenger.certs_dir = "/etc/nginx/certs" 10 | default.nginx_passenger.ruby = "/usr/bin/ruby" 11 | default.nginx_passenger.max_pool_size = 8 12 | default.nginx_passenger.max_instances_per_app = 0 13 | default.nginx_passenger.min_instances = 2 14 | default.nginx_passenger.pool_idle_time = 300 15 | default.nginx_passenger.max_requests = 0 16 | 17 | default.nginx_passenger.cert_databag = "ssl_certs" 18 | default.nginx_passenger.cert_authority = "Self Signed" 19 | 20 | default.nginx_passenger.redirect_to_https = true 21 | default.nginx_passenger.site_min_instances = 2 22 | default.nginx_passenger.site_max_body_size = "8M" 23 | default.nginx_passenger.keep_env_path = true 24 | default.nginx_passenger.default_log_format = "combined" 25 | 26 | default.nginx_passenger.maintenance_page = nil 27 | default.nginx_passenger.maintenance_check = nil 28 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name "nginx_passenger" 2 | maintainer "Eric Richardson" 3 | maintainer_email "e@ewr.is" 4 | license "BSD" 5 | source_url "https://github.com/ewr/nginx_passenger-cookbook" 6 | issues_url "https://github.com/ewr/nginx_passenger-cookbook/issues" 7 | description "Installs/Configures nginx and Passenger on Ubuntu" 8 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 9 | version "0.5.7" 10 | 11 | supports 'ubuntu' 12 | 13 | depends "apt" 14 | depends "ssl_certificate" 15 | -------------------------------------------------------------------------------- /providers/site.rb: -------------------------------------------------------------------------------- 1 | action :create do 2 | # -- Are we installing an SSL site? -- # 3 | 4 | cert_exists = false 5 | 6 | if (new_resource.cert && new_resource.cert != "skip") || new_resource.generate_cert 7 | directory node.nginx_passenger.certs_dir do 8 | action :create 9 | recursive true 10 | end 11 | end 12 | 13 | if new_resource.cert && new_resource.cert != "skip" 14 | # Look up SSL cert in databag 15 | cert = data_bag_item(node.nginx_passenger.cert_databag,new_resource.cert) 16 | 17 | if cert 18 | # TODO: Need to make sure cert has cert and key 19 | 20 | cert.keys.each do |k| 21 | file "#{node.nginx_passenger.certs_dir}/#{new_resource.name}.#{k}" do 22 | backup 1 23 | mode 0644 24 | content cert[k] 25 | notifies :reload, "service[nginx]" 26 | end 27 | end 28 | 29 | cert_exists = true 30 | 31 | else 32 | # need to error that the specified SSL cert wasn't found 33 | end 34 | end 35 | 36 | if new_resource.generate_cert 37 | 38 | ssl_certificate new_resource.server do 39 | action :create 40 | common_name new_resource.server 41 | organization node.nginx_passenger.cert_authority 42 | key_path "#{node.nginx_passenger.certs_dir}/#{new_resource.name}.key" 43 | cert_path "#{node.nginx_passenger.certs_dir}/#{new_resource.name}.cert" 44 | source "self-signed" 45 | end 46 | 47 | cert_exists = true 48 | 49 | end 50 | 51 | # -- Create nginx site file -- # 52 | 53 | log_format = new_resource.log_format || node.nginx_passenger.default_log_format 54 | 55 | template "#{node.nginx_passenger.sites_dir}/#{new_resource.name}" do 56 | if new_resource.template 57 | source new_resource.template 58 | else 59 | source "site.conf.erb" 60 | cookbook "nginx_passenger" 61 | end 62 | 63 | mode 0644 64 | 65 | variables({:resource => new_resource,:cert_exists => cert_exists,:log_format => log_format}) 66 | 67 | notifies :reload, "service[nginx]" 68 | end 69 | end 70 | 71 | #---------- 72 | 73 | action :delete do 74 | # -- Define nginx service (just in case) -- # 75 | 76 | service "nginx" do 77 | provider Chef::Provider::Service::Upstart 78 | action :nothing 79 | supports :start => true, :restart => true, :reload => true 80 | end 81 | 82 | # -- Delete nginx site file -- # 83 | 84 | file "#{node.nginx_passenger.sites_dir}/#{new_resource.name}" do 85 | action :delete 86 | notifies :reload, "service[nginx]", :immediately 87 | end 88 | 89 | # -- Delete any certs -- # 90 | 91 | execute "remove-#{new_resource.name}-certs" do 92 | command "rm -f #{node.nginx_passenger.certs_dir}/#{new_resource.name}*" 93 | action :run 94 | end 95 | end -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Installs nginx and Passenger from Phusion's oss-binaries repo 2 | 3 | include_recipe "apt" 4 | 5 | # -- Make sure apt HTTPS is installed -- # 6 | 7 | package "apt-transport-https" 8 | 9 | # -- Add repo -- # 10 | 11 | # Phusion provides two repos: one that cotains Passenger 5, and one that 12 | # contains Passenger 4. Use the appropriate one based on the 13 | # `nginx_passenger.use_passenger_4` attribute boolean 14 | apt_uri = node.nginx_passenger.use_passenger_4 ? "https://oss-binaries.phusionpassenger.com/apt/passenger/4" : "https://oss-binaries.phusionpassenger.com/apt/passenger" 15 | 16 | apt_repository "phusion" do 17 | action :add 18 | uri apt_uri 19 | distribution node.lsb.codename 20 | components ['main'] 21 | keyserver "hkp://keyserver.ubuntu.com:80" 22 | key "561F9B9CAC40B2F7" 23 | end 24 | 25 | # -- Install packages -- # 26 | 27 | package "nginx-common" do 28 | options '-o DPkg::Options::="--force-confold"' 29 | end 30 | 31 | package "passenger" 32 | package "nginx-extras" 33 | 34 | # -- Define a service we can use later -- # 35 | 36 | service "nginx" do 37 | action [:enable,:start] 38 | supports [:enable,:start,:stop,:disable,:reload,:restart] 39 | end 40 | 41 | # -- Install nginx config with Passenger -- # 42 | 43 | template "/etc/nginx/nginx.conf" do 44 | action :create 45 | notifies :restart, "service[nginx]" 46 | end 47 | 48 | # -- Make sure sites directory exists -- # 49 | 50 | directory node.nginx_passenger.sites_dir do 51 | action :create 52 | recursive true 53 | mode 0755 54 | end 55 | 56 | # -- Make sure logs directory exists -- # 57 | 58 | directory node.nginx_passenger.log_dir do 59 | action :create 60 | recursive true 61 | mode 0755 62 | owner "www-data" 63 | end 64 | 65 | # -- Should we create an empty default site? -- # 66 | 67 | template "#{node.nginx_passenger.sites_dir}/DEFAULT" do 68 | action node.nginx_passenger.catch_default ? :create : :delete 69 | notifies :reload, "service[nginx]" 70 | end -------------------------------------------------------------------------------- /resources/site.rb: -------------------------------------------------------------------------------- 1 | actions :delete 2 | default_action :create 3 | attribute :name, :kind_of => String 4 | attribute :server, :kind_of => String 5 | attribute :rails_env, :kind_of => String 6 | attribute :dir, :kind_of => String 7 | attribute :ruby, :kind_of => String 8 | attribute :cert, :kind_of => String 9 | attribute :generate_cert, :kind_of => [TrueClass,FalseClass], :default => false 10 | attribute :http, :kind_of => [TrueClass,FalseClass], :default => false 11 | attribute :template, :kind_of => String 12 | attribute :min_instances, :kind_of => Integer 13 | attribute :max_body_size, :kind_of => String 14 | attribute :env, :kind_of => String 15 | attribute :user, :kind_of => String 16 | attribute :custom, :kind_of => Hash 17 | attribute :maintenance_page, :kind_of => String 18 | attribute :maintenance_check, :kind_of => String 19 | attribute :log_format, :kind_of => String 20 | attribute :static, :kind_of => [TrueClass,FalseClass], :default => false -------------------------------------------------------------------------------- /templates/default/DEFAULT.erb: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | server_name ""; 4 | 5 | access_log <%= node.nginx_passenger.log_dir %>/default.access.log; 6 | 7 | return 404; 8 | } -------------------------------------------------------------------------------- /templates/default/nginx.conf.erb: -------------------------------------------------------------------------------- 1 | # THIS FILE IS MANAGED BY CHEF's nginx_passenger COOKBOOK. 2 | 3 | user www-data; 4 | worker_processes <%= node.nginx_passenger.nginx_workers %>; 5 | pid /var/run/nginx.pid; 6 | 7 | <% if node.nginx_passenger.keep_env_path %> 8 | env PATH; 9 | <% end %> 10 | 11 | events { 12 | worker_connections <%= node.nginx_passenger.nginx_connections %>; 13 | # multi_accept on; 14 | } 15 | 16 | http { 17 | 18 | ## 19 | # Basic Settings 20 | ## 21 | 22 | sendfile on; 23 | tcp_nopush on; 24 | tcp_nodelay on; 25 | keepalive_timeout 65; 26 | types_hash_max_size 2048; 27 | # server_tokens off; 28 | 29 | # server_names_hash_bucket_size 64; 30 | # server_name_in_redirect off; 31 | 32 | include /etc/nginx/mime.types; 33 | default_type application/octet-stream; 34 | 35 | ## 36 | # Logging Settings 37 | ## 38 | 39 | access_log /var/log/nginx/access.log; 40 | error_log /var/log/nginx/error.log; 41 | 42 | ## 43 | # Gzip Settings 44 | ## 45 | 46 | gzip on; 47 | gzip_disable "msie6"; 48 | 49 | # gzip_vary on; 50 | # gzip_proxied any; 51 | # gzip_comp_level 6; 52 | # gzip_buffers 16 8k; 53 | # gzip_http_version 1.1; 54 | # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 55 | 56 | ## 57 | # nginx-naxsi config 58 | ## 59 | # Uncomment it if you installed nginx-naxsi 60 | ## 61 | 62 | # include /etc/nginx/naxsi_core.rules; 63 | 64 | ## 65 | # Passenger config 66 | ## 67 | 68 | passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; 69 | passenger_ruby <%= node.nginx_passenger.ruby %>; 70 | passenger_max_pool_size <%= node.nginx_passenger.max_pool_size %>; 71 | passenger_max_instances_per_app <%= node.nginx_passenger.max_instances_per_app %>; 72 | passenger_min_instances <%= node.nginx_passenger.min_instances %>; 73 | passenger_pool_idle_time <%= node.nginx_passenger.pool_idle_time %>; 74 | passenger_max_requests <%= node.nginx_passenger.max_requests %>; 75 | 76 | # -- Logging Format -- # 77 | 78 | log_format combined_timing '$remote_addr - $remote_user [$time_local] ' 79 | '"$request" $status $body_bytes_sent ' 80 | '"$http_referer" "$http_user_agent" ' 81 | '$request_time $upstream_response_time $pipe'; 82 | 83 | ## 84 | # Virtual Host Configs 85 | ## 86 | 87 | include /etc/nginx/conf.d/*.conf; 88 | include <%= node.nginx_passenger.sites_dir %>/*; 89 | } 90 | -------------------------------------------------------------------------------- /templates/default/site.conf.erb: -------------------------------------------------------------------------------- 1 | <% if @cert_exists %> 2 | 3 | server { 4 | listen 443 ssl; 5 | ssl on; 6 | server_name <%= @resource.server %>; 7 | 8 | ssl_certificate <%= node.nginx_passenger.certs_dir %>/<%= @resource.name %>.cert; 9 | ssl_certificate_key <%= node.nginx_passenger.certs_dir %>/<%= @resource.name %>.key; 10 | 11 | access_log <%= node.nginx_passenger.log_dir %>/<%= @resource.name %>.ssl.access.log <%= @log_format %>; 12 | error_log <%= node.nginx_passenger.log_dir %>/<%= @resource.name %>.ssl.error.log; 13 | 14 | location / { 15 | <% if @resource.static %> 16 | root <%= @resource.dir %> 17 | <% else %> 18 | passenger_enabled on; 19 | 20 | <% if @resource.ruby %> 21 | passenger_ruby <%= @resource.ruby %>; 22 | <% end %> 23 | 24 | root <%= @resource.dir %>/public; 25 | 26 | <% if @resource.env %> 27 | passenger_app_env "<%= @resource.env %>"; 28 | <% elsif @resource.rails_env %> 29 | rails_env "<%= @resource.rails_env %>"; 30 | <% end %> 31 | 32 | <% if @resource.user %> 33 | passenger_user "<%= @resource.user %>"; 34 | <% end %> 35 | 36 | passenger_min_instances <%= @resource.min_instances || node.nginx_passenger.site_min_instances %>; 37 | 38 | client_max_body_size <%= @resource.max_body_size || node.nginx_passenger.site_max_body_size %>; 39 | <% end %> 40 | } 41 | 42 | <% if @resource.maintenance_page %> 43 | if (-f <%= @resource.maintenance_check || "#{@resource.dir}/IN_MAINTENANCE_MODE" %>) { 44 | return 503; 45 | } 46 | 47 | error_page 503 @maintenance; 48 | 49 | location @maintenance { 50 | root <%= @resource.dir %>/public; 51 | 52 | if (!-f <%= @resource.dir %>/public$uri) { 53 | rewrite ^(.*)$ <%= @resource.maintenance_page %> break; 54 | } 55 | } 56 | <% end %> 57 | } 58 | 59 | <% if !@resource.http && node.nginx_passenger.redirect_to_https %> 60 | 61 | server { 62 | listen 80; 63 | server_name <%= @resource.server %>; 64 | return 301 https://<%= @resource.server %>$request_uri; 65 | } 66 | 67 | <% end %> 68 | 69 | <% end %> 70 | 71 | <% if !@cert_exists || @resource.http %> 72 | 73 | server { 74 | listen 80; 75 | server_name <%= @resource.server %>; 76 | 77 | access_log <%= node.nginx_passenger.log_dir %>/<%= @resource.name %>.access.log <%= @log_format %>; 78 | error_log <%= node.nginx_passenger.log_dir %>/<%= @resource.name %>.error.log; 79 | 80 | location / { 81 | <% if @resource.static %> 82 | root <%= @resource.dir %>; 83 | <% else %> 84 | passenger_enabled on; 85 | 86 | <% if @resource.ruby %> 87 | passenger_ruby <%= @resource.ruby %>; 88 | <% end %> 89 | 90 | root <%= @resource.dir %>/public; 91 | 92 | <% if @resource.env %> 93 | passenger_app_env "<%= @resource.env %>"; 94 | <% elsif @resource.rails_env %> 95 | rails_env "<%= @resource.rails_env %>"; 96 | <% end %> 97 | 98 | <% if @resource.user %> 99 | passenger_user "<%= @resource.user %>"; 100 | <% end %> 101 | 102 | passenger_min_instances <%= @resource.min_instances || node.nginx_passenger.site_min_instances %>; 103 | 104 | client_max_body_size <%= @resource.max_body_size || node.nginx_passenger.site_max_body_size %>; 105 | <% end %> 106 | } 107 | 108 | <% if @resource.maintenance_page %> 109 | if (-f <%= @resource.maintenance_check || "#{@resource.dir}/IN_MAINTENANCE_MODE" %>) { 110 | return 503; 111 | } 112 | 113 | error_page 503 @maintenance; 114 | 115 | location @maintenance { 116 | root <%= @resource.dir %>/public; 117 | 118 | if (!-f <%= @resource.dir %>/public$uri) { 119 | rewrite ^(.*)$ <%= @resource.maintenance_page %> break; 120 | } 121 | } 122 | <% end %> 123 | } 124 | 125 | <% end %> 126 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/localhost/nginx_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | # nginx should be running 4 | describe service("nginx") do 5 | it { should be_running } 6 | end 7 | 8 | # nginx config should point to the sites dir 9 | describe file("/etc/nginx/nginx.conf") do 10 | it { should be_file } 11 | its(:content) { should include("include /etc/nginx/sites/*;") } 12 | end 13 | 14 | # make sure the sites dir exists 15 | 16 | describe file("/etc/nginx/sites") do 17 | it { should be_directory } 18 | #it { should be_owned_by("www-data") } 19 | end 20 | 21 | # make sure the logs dir exists 22 | 23 | describe file("/var/log/nginx-sites") do 24 | it { should be_directory } 25 | it { should be_owned_by("www-data") } 26 | end 27 | 28 | # -- test working site -- # 29 | 30 | describe command("curl -H 'Host: test.kitchen' http://localhost") do 31 | its(:exit_status) { should eq 0 } 32 | its(:stdout) { should include("OK! test.kitchen") } 33 | end 34 | 35 | # check for timing information on the access log 36 | describe command("tail -1 /var/log/nginx-sites/test.access.log") do 37 | its(:stdout) { should match(/" [\d\.]+ [\d\.]+ \.$/) } 38 | end 39 | 40 | # -- test self-signed cert site -- # 41 | 42 | describe command("curl -k -v -H 'Host: certtest.kitchen' https://localhost") do 43 | its(:exit_status) { should eq 0 } 44 | its(:stdout) { should include("OK! certtest.kitchen") } 45 | its(:stderr) { should include("subject: O=Self Signed") } 46 | end 47 | 48 | # -- test maintenance site -- # 49 | 50 | describe command("curl -H 'Host: maintenance.kitchen' localhost") do 51 | its(:exit_status) { should eq 0 } 52 | its(:stdout) { should include("Under Construction") } 53 | end 54 | 55 | describe command("curl -H 'Host: maintenance.kitchen' http://localhost/foo.txt") do 56 | its(:exit_status) { should eq 0 } 57 | its(:stdout) { should include("BAR") } 58 | end 59 | 60 | # there should be no timing data here... 61 | describe command("tail -1 /var/log/nginx-sites/maintenance.access.log") do 62 | its(:stdout) { should match(/"$/) } 63 | end 64 | 65 | # -- test static site -- # 66 | 67 | describe command("curl -H 'Host: static.kitchen' localhost") do 68 | its(:exit_status) { should eq 0 } 69 | its(:stdout) { should include("Testing Static!") } 70 | end 71 | 72 | # -- test IP for 404 (catch default) -- # 73 | 74 | describe command("curl localhost") do 75 | its(:exit_status) { should eq 0 } 76 | its(:stdout) { should include("404 Not Found") } 77 | end 78 | 79 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | set :backend, :exec 3 | -------------------------------------------------------------------------------- /test/integration/passenger4/serverspec/localhost/nginx_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | # nginx should be running 4 | describe service("nginx") do 5 | it { should be_running } 6 | end 7 | 8 | # nginx config should point to the sites dir 9 | describe file("/etc/nginx/nginx.conf") do 10 | it { should be_file } 11 | its(:content) { should include("include /etc/nginx/sites/*;") } 12 | end 13 | 14 | # make sure the sites dir exists 15 | 16 | describe file("/etc/nginx/sites") do 17 | it { should be_directory } 18 | #it { should be_owned_by("www-data") } 19 | end 20 | 21 | # make sure the logs dir exists 22 | 23 | describe file("/var/log/nginx-sites") do 24 | it { should be_directory } 25 | it { should be_owned_by("www-data") } 26 | end 27 | 28 | # -- test working site -- # 29 | 30 | describe command("curl -H 'Host: test.kitchen' http://localhost") do 31 | its(:exit_status) { should eq 0 } 32 | its(:stdout) { should include("OK! test.kitchen") } 33 | end 34 | 35 | # check for timing information on the access log 36 | describe command("tail -1 /var/log/nginx-sites/test.access.log") do 37 | its(:stdout) { should match(/" [\d\.]+ [\d\.]+ \.$/) } 38 | end 39 | 40 | # -- test self-signed cert site -- # 41 | 42 | describe command("curl -k -v -H 'Host: certtest.kitchen' https://localhost") do 43 | its(:exit_status) { should eq 0 } 44 | its(:stdout) { should include("OK! certtest.kitchen") } 45 | its(:stderr) { should include("subject: O=Self Signed") } 46 | end 47 | 48 | # -- test maintenance site -- # 49 | 50 | describe command("curl -H 'Host: maintenance.kitchen' localhost") do 51 | its(:exit_status) { should eq 0 } 52 | its(:stdout) { should include("Under Construction") } 53 | end 54 | 55 | describe command("curl -H 'Host: maintenance.kitchen' http://localhost/foo.txt") do 56 | its(:exit_status) { should eq 0 } 57 | its(:stdout) { should include("BAR") } 58 | end 59 | 60 | # there should be no timing data here... 61 | describe command("tail -1 /var/log/nginx-sites/maintenance.access.log") do 62 | its(:stdout) { should match(/"$/) } 63 | end 64 | 65 | # -- test static site -- # 66 | 67 | describe command("curl -H 'Host: static.kitchen' localhost") do 68 | its(:exit_status) { should eq 0 } 69 | its(:stdout) { should include("Testing Static!") } 70 | end 71 | 72 | # -- test IP for 404 (catch default) -- # 73 | 74 | describe command("curl localhost") do 75 | its(:exit_status) { should eq 0 } 76 | its(:stdout) { should include("404 Not Found") } 77 | end 78 | 79 | -------------------------------------------------------------------------------- /test/integration/passenger4/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'serverspec' 2 | set :backend, :exec 3 | -------------------------------------------------------------------------------- /test/test-cookbook/metadata.rb: -------------------------------------------------------------------------------- 1 | name "nginx_passenger-test" 2 | maintainer "Eric Richardson" 3 | maintainer_email "e@ewr.is" 4 | license "BSD" 5 | description "" 6 | long_description "" 7 | version "0.0.1" 8 | 9 | depends "nginx_passenger" 10 | -------------------------------------------------------------------------------- /test/test-cookbook/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # for the test suite... 2 | package "curl" 3 | 4 | # -- Create working test site -- # 5 | 6 | # Create the directory for our web server 7 | ['/web/test','/web/test/public'].each do |d| 8 | directory d do 9 | owner "www-data" 10 | group "www-data" 11 | mode 0755 12 | action :create 13 | recursive true 14 | end 15 | end 16 | 17 | template "/web/test/config.ru" do 18 | action :create 19 | owner "www-data" 20 | group "www-data" 21 | mode 0755 22 | variables({ :server => "test.kitchen" }) 23 | end 24 | 25 | # Create the default test site 26 | nginx_passenger_site "test" do 27 | action :create 28 | server "test.kitchen" 29 | cert "skip" 30 | dir "/web/test" 31 | log_format "combined_timing" 32 | end 33 | 34 | # -- Create site with a self-signed cert -- # 35 | 36 | # Create the directory for our web server 37 | ['/web/certtest','/web/certtest/public'].each do |d| 38 | directory d do 39 | owner "www-data" 40 | group "www-data" 41 | mode 0755 42 | action :create 43 | recursive true 44 | end 45 | end 46 | 47 | template "/web/certtest/config.ru" do 48 | action :create 49 | owner "www-data" 50 | group "www-data" 51 | mode 0755 52 | variables({ :server => "certtest.kitchen" }) 53 | end 54 | 55 | # Create the default test site 56 | nginx_passenger_site "certtest" do 57 | action :create 58 | server "certtest.kitchen" 59 | generate_cert true 60 | dir "/web/certtest" 61 | log_format "combined_timing" 62 | end 63 | 64 | # -- Create maintenance mode site -- # 65 | 66 | # Create the directory for our web server 67 | ['/web/maintenance','/web/maintenance/public'].each do |d| 68 | directory d do 69 | owner "www-data" 70 | group "www-data" 71 | mode 0755 72 | action :create 73 | recursive true 74 | end 75 | end 76 | 77 | # write our maintenance mode flag 78 | file "/web/maintenance/IN_MAINTENANCE_MODE" do 79 | action :touch 80 | owner "www-data" 81 | group "www-data" 82 | end 83 | 84 | # Create our foo.html page 85 | file "/web/maintenance/public/foo.txt" do 86 | action :create 87 | mode 0644 88 | group "www-data" 89 | owner "www-data" 90 | content "BAR\n" 91 | end 92 | 93 | # Create our maintenance.html page 94 | template "/web/maintenance/public/maintenance.html" do 95 | action :create 96 | mode 0644 97 | group "www-data" 98 | owner "www-data" 99 | end 100 | 101 | template "/web/maintenance/config.ru" do 102 | action :create 103 | owner "www-data" 104 | group "www-data" 105 | mode 0755 106 | variables({ :server => "maintenance.kitchen" }) 107 | end 108 | 109 | nginx_passenger_site "maintenance" do 110 | action :create 111 | server "maintenance.kitchen" 112 | cert "skip" 113 | dir "/web/maintenance" 114 | maintenance_page "/maintenance.html" 115 | end 116 | 117 | # -- Create static site -- # 118 | 119 | # Create the directory for our web server 120 | ['/web/static'].each do |d| 121 | directory d do 122 | owner "www-data" 123 | group "www-data" 124 | mode 0755 125 | action :create 126 | recursive true 127 | end 128 | end 129 | 130 | file "/web/static/index.html" do 131 | action :create 132 | content "