Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a custom counter vhost so .gif isn't short-circuited by nginx.

  • Loading branch information...
commit ec6bc28241a7ba293b386c11481ad908cd1e780e 1 parent f8082d6
Ben Hoskings authored April 05, 2012
9  counter.rb
@@ -17,6 +17,15 @@
17 17
       :data_required => 'no'
18 18
     ),
19 19
 
  20
+    # Replace the default config with our own.
  21
+    'vhost enabled'.with(
  22
+      :app_name => 'counter',
  23
+      :domain => domain,
  24
+      :path => app_root,
  25
+      :enable_https => 'yes',
  26
+      :force_https => 'no'
  27
+    ),
  28
+
20 29
     # For the dw.theconversation.edu.au -> backup.tc-dev.net psql/ssh connection.
21 30
     'read-only db access'.with(
22 31
       :db_name => YAML.load_file(app_root / 'config/database.yml')[env.to_s]['database'],
55  nginx/counter_vhost.conf.erb
... ...
@@ -0,0 +1,55 @@
  1
+upstream <%= upstream_name %> {
  2
+  # fail_timeout=0 means we always retry the unicorn master, since it's
  3
+  # responsible for restarting workers when they fail.
  4
+  server unix:<%= unicorn_socket %> fail_timeout=0;
  5
+}
  6
+
  7
+server {
  8
+  charset utf-8;
  9
+
  10
+  <% if enable_http[/^y/] %>
  11
+  listen <%= listen_host %>:<%= listen_port %>;
  12
+  <% end %>
  13
+
  14
+  <% if enable_https[/^y/] %>
  15
+  listen <%= listen_host %>:443 ssl;
  16
+  ssl                  on;
  17
+  ssl_certificate      certs/<%= domain %>.crt;
  18
+  ssl_certificate_key  certs/<%= domain %>.key;
  19
+  ssl_session_timeout  5m;
  20
+  ssl_ciphers          HIGH:!aNULL:!MD5:!kEDH;
  21
+
  22
+    <% if force_https[/^y/] %>
  23
+  rewrite ^(.*)$ https://<%= domain %>$1 redirect;
  24
+    <% end %>
  25
+  <% end %>
  26
+
  27
+  server_name <%= server_names.join(' ') %>;
  28
+  root <%= path / 'public' %>;
  29
+
  30
+  if ($host !~ ^<%= domain.to_s.gsub('.', '\.') %>$) {
  31
+    rewrite ^(.*)$ http://<%= domain %>$1 permanent;
  32
+  }
  33
+
  34
+  error_page 503 /system/maintenance.html;
  35
+  location /system/maintenance.html { return 503; }
  36
+
  37
+  try_files $uri/index.html $uri.html $uri /system/maintenance.html @app;
  38
+
  39
+  # POSTs are intended for the app, not cached pages. We use '=' to let @app set the response code.
  40
+  error_page 405 = @app;
  41
+
  42
+  location @app {
  43
+    proxy_pass           http://<%= upstream_name %>;
  44
+    proxy_redirect       off;
  45
+
  46
+    proxy_buffer_size    64k;
  47
+    proxy_buffers        32 16k;
  48
+    client_max_body_size 128m;
  49
+
  50
+    proxy_set_header     Host              $host;
  51
+    proxy_set_header     X-Real-IP         $remote_addr;
  52
+    proxy_set_header     X-Forwarded-For   $proxy_add_x_forwarded_for;
  53
+    proxy_set_header     X-Forwarded-Proto $scheme;
  54
+  }
  55
+}

0 notes on commit ec6bc28

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