Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
19  nginx.rb
@@ -44,21 +44,16 @@ def restart_nginx
44 44
   proxy_host.default('localhost')
45 45
   proxy_port.default('8000')
46 46
 
47  
-  # TODO: Hardcode this temporarily, until the migration is complete.
48  
-  def listen_host_dot_com
  47
+  # TODO: Only required until we move to a single-IP nginx config.
  48
+  def listen_host_au
49 49
     {
50  
-      '74.50.63.170' => '74.50.63.173',
51  
-      '31.193.141.103' => '91.186.19.133'
  50
+      '74.50.63.173' => '74.50.63.170',
  51
+      '91.186.19.133' => '31.193.141.103'
52 52
     }[listen_host.to_s]
53 53
   end
54  
-  def domain_dot_com
55  
-    'theconversation.com'
56  
-  end
57  
-
58  
-  def listen_host_uk; listen_host_dot_com; end
59  
-  def domain_uk
60  
-    'theconversation.org.uk'
61  
-  end
  54
+  def listen_host_uk; listen_host; end
  55
+  def domain_au; 'theconversation.edu.au' end
  56
+  def domain_uk; 'theconversation.org.uk' end
62 57
 
63 58
   def www_aliases
64 59
     "#{domain} #{domain_aliases}".split(/\s+/).reject {|d|
75  nginx/tc_vhost.conf.erb
... ...
@@ -1,31 +1,33 @@
  1
+# The unicorn appserver.
1 2
 upstream <%= upstream_name %> {
2 3
   # fail_timeout=0 means we always retry the unicorn master, since it's
3 4
   # responsible for restarting workers when they fail.
4 5
   server unix:<%= unicorn_socket %> fail_timeout=0;
5 6
 }
6 7
 
  8
+# Canonical www. redirect
7 9
 server {
8 10
   listen <%= listen_host %>:<%= listen_port %>;
9 11
   server_name www.<%= domain %>;
10 12
   return 301 http://<%= domain %>$request_uri;
11 13
 }
12 14
 
13  
-<% if env == 'production' %>
  15
+# Canonical http:// vhost
14 16
 server {
15  
-  listen <%= listen_host_dot_com %>:<%= listen_port %>;
16  
-  server_name www.<%= domain_dot_com %>;
17  
-  return 301 http://<%= domain_dot_com %>$request_uri;
18  
-}
  17
+  listen <%= listen_host %>:<%= listen_port %>;
  18
+  server_name <%= domain %>;
19 19
 
20  
-server {
21  
-  listen <%= listen_host_uk %>:<%= listen_port %>;
22  
-  server_name www.<%= domain_uk %>;
23  
-  return 301 http://<%= domain_uk %>$request_uri;
  20
+  # Redirect authed users to https. (The app does this too; we redirect
  21
+  # cached pages here to avoid having to do it on the frontend.)
  22
+  if ($http_cookie ~ 'user_tracer_engage') {
  23
+    return 301 https://<%= domain %>$request_uri;
  24
+  }
  25
+
  26
+  include vhosts/<%= domain %>.common;
24 27
 }
25  
-<% end %>
26 28
 
  29
+# Canonical https:// vhost
27 30
 server {
28  
-  listen <%= listen_host %>:<%= listen_port %>;
29 31
   listen <%= listen_host %>:443 ssl;
30 32
   server_name <%= domain %>;
31 33
 
@@ -34,52 +36,53 @@ server {
34 36
   ssl_session_timeout  5m;
35 37
   ssl_ciphers          HIGH:!aNULL:!MD5:!kEDH;
36 38
 
37  
-  <% if env == 'production' %>
38  
-  # All traffic is redirected to .com
39  
-  location = / {
40  
-    return 301 $scheme://<%= domain_dot_com %>/au;
41  
-  }
42  
-  location / {
43  
-    return 301 $scheme://<%= domain_dot_com %>$request_uri;
44  
-  }
45  
-  <% end %>
  39
+  include vhosts/<%= domain %>.common;
46 40
 }
47 41
 
48 42
 <% if env == 'production' %>
  43
+# AU www. redirect
49 44
 server {
50  
-  listen <%= listen_host_dot_com %>:<%= listen_port %>;
51  
-  server_name <%= domain_dot_com %>;
52  
-
53  
-  # Redirect authed users to https. (The app does this too; we redirect
54  
-  # cached pages here to avoid having to do it on the frontend.)
55  
-  if ($http_cookie ~ 'user_tracer_engage') {
56  
-    rewrite ^(.*)$ https://$host$1 redirect;
57  
-  }
  45
+  listen <%= listen_host_au %>:<%= listen_port %>;
  46
+  server_name www.<%= domain_au %>;
  47
+  return 301 http://<%= domain_au %>$request_uri;
  48
+}
58 49
 
59  
-  include vhosts/<%= domain %>.common;
  50
+# UK www. redirect
  51
+server {
  52
+  listen <%= listen_host_uk %>:<%= listen_port %>;
  53
+  server_name www.<%= domain_uk %>;
  54
+  return 301 http://<%= domain_uk %>$request_uri;
60 55
 }
61 56
 
  57
+# AU -> canonical redirect
62 58
 server {
63  
-  listen <%= listen_host_dot_com %>:443 ssl;
64  
-  server_name <%= domain_dot_com %>;
  59
+  listen <%= listen_host_au %>:<%= listen_port %>;
  60
+  listen <%= listen_host_au %>:443 ssl;
  61
+  server_name <%= domain_au %>;
65 62
 
66  
-  ssl_certificate      certs/<%= domain_dot_com %>.crt;
67  
-  ssl_certificate_key  certs/<%= domain_dot_com %>.key;
  63
+  ssl_certificate      certs/<%= domain_au %>.crt;
  64
+  ssl_certificate_key  certs/<%= domain_au %>.key;
68 65
   ssl_session_timeout  5m;
69 66
   ssl_ciphers          HIGH:!aNULL:!MD5:!kEDH;
70 67
 
71  
-  include vhosts/<%= domain %>.common;
  68
+  location = / {
  69
+    return 301 $scheme://<%= domain %>/au;
  70
+  }
  71
+  location / {
  72
+    return 301 $scheme://<%= domain %>$request_uri;
  73
+  }
72 74
 }
73 75
 
  76
+# UK -> canonical redirect
74 77
 server {
75 78
   listen <%= listen_host_uk %>:<%= listen_port %>;
76 79
   server_name <%= domain_uk %>;
77 80
 
78 81
   location = / {
79  
-    return 301 $scheme://<%= domain_dot_com %>/uk;
  82
+    return 301 $scheme://<%= domain %>/uk;
80 83
   }
81 84
   location / {
82  
-    return 301 $scheme://<%= domain_dot_com %>$request_uri;
  85
+    return 301 $scheme://<%= domain %>$request_uri;
83 86
   }
84 87
 }
85 88
 <% end %>

No commit comments for this range

Something went wrong with that request. Please try again.