Permalink
Browse files

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

  • Loading branch information...
1 parent f8082d6 commit ec6bc28241a7ba293b386c11481ad908cd1e780e @benhoskings benhoskings committed Apr 5, 2012
Showing with 64 additions and 0 deletions.
  1. +9 −0 counter.rb
  2. +55 −0 nginx/counter_vhost.conf.erb
View
@@ -17,6 +17,15 @@
:data_required => 'no'
),
+ # Replace the default config with our own.
+ 'vhost enabled'.with(
+ :app_name => 'counter',
+ :domain => domain,
+ :path => app_root,
+ :enable_https => 'yes',
+ :force_https => 'no'
+ ),
+
# For the dw.theconversation.edu.au -> backup.tc-dev.net psql/ssh connection.
'read-only db access'.with(
:db_name => YAML.load_file(app_root / 'config/database.yml')[env.to_s]['database'],
@@ -0,0 +1,55 @@
+upstream <%= upstream_name %> {
+ # fail_timeout=0 means we always retry the unicorn master, since it's
+ # responsible for restarting workers when they fail.
+ server unix:<%= unicorn_socket %> fail_timeout=0;
+}
+
+server {
+ charset utf-8;
+
+ <% if enable_http[/^y/] %>
+ listen <%= listen_host %>:<%= listen_port %>;
+ <% end %>
+
+ <% if enable_https[/^y/] %>
+ listen <%= listen_host %>:443 ssl;
+ ssl on;
+ ssl_certificate certs/<%= domain %>.crt;
+ ssl_certificate_key certs/<%= domain %>.key;
+ ssl_session_timeout 5m;
+ ssl_ciphers HIGH:!aNULL:!MD5:!kEDH;
+
+ <% if force_https[/^y/] %>
+ rewrite ^(.*)$ https://<%= domain %>$1 redirect;
+ <% end %>
+ <% end %>
+
+ server_name <%= server_names.join(' ') %>;
+ root <%= path / 'public' %>;
+
+ if ($host !~ ^<%= domain.to_s.gsub('.', '\.') %>$) {
+ rewrite ^(.*)$ http://<%= domain %>$1 permanent;
+ }
+
+ error_page 503 /system/maintenance.html;
+ location /system/maintenance.html { return 503; }
+
+ try_files $uri/index.html $uri.html $uri /system/maintenance.html @app;
+
+ # POSTs are intended for the app, not cached pages. We use '=' to let @app set the response code.
+ error_page 405 = @app;
+
+ location @app {
+ proxy_pass http://<%= upstream_name %>;
+ proxy_redirect off;
+
+ proxy_buffer_size 64k;
+ proxy_buffers 32 16k;
+ client_max_body_size 128m;
+
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ }
+}

0 comments on commit ec6bc28

Please sign in to comment.