|
1 | | -<% main_hostname = node.read('nginx_custom', 'main_hostname') || "#{@application[:domains].join(" ")} #{node['hostname']}" %> |
| 1 | +<% host_redirects = node.read('nginx_custom', 'host_redirects') || {} %> |
| 2 | +<% regex = node.read('nginx_custom', 'mobile_api_paths_regex') %> |
2 | 3 |
|
3 | 4 | upstream <%= @name %>_<%= @application[:domains].first %> { |
4 | 5 | server unix:<%= @deploy_dir.to_s %>/shared/sockets/<%= @name %>.sock fail_timeout=0; |
5 | 6 | } |
| 7 | +<% main_hostnames = host_redirects.keys.presence || ["#{@application[:domains].join(" ")} #{node['hostname']}"] %> |
| 8 | +<% main_hostnames.each do |main_hostname| %> |
| 9 | + server { |
| 10 | + server_name <%= main_hostname %>; |
6 | 11 |
|
7 | | -server { |
8 | | - server_name <%= main_hostname %>; |
9 | | - |
10 | | - include /srv/www/jiffyshirts/current/config/nginx/server_common.conf; |
11 | | - |
12 | | - location / { |
13 | | - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
14 | | - proxy_set_header Host $http_host; |
15 | | - proxy_redirect off; |
| 12 | + include /srv/www/jiffyshirts/current/config/nginx/server_common.conf; |
16 | 13 |
|
17 | | - if (-f $document_root/offline) { |
18 | | - return 503; |
| 14 | + location / { |
| 15 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 16 | + proxy_set_header Host $http_host; |
| 17 | + proxy_redirect off; |
| 18 | + |
| 19 | + if (-f $document_root/offline) { |
| 20 | + return 503; |
| 21 | + } |
| 22 | + |
| 23 | + # If you don't find the filename in the static files |
| 24 | + # Then request it from the unicorn server |
| 25 | + if (!-f $request_filename) { |
| 26 | + proxy_pass http://unicorn_jiffyshirts; |
| 27 | + break; |
| 28 | + } |
19 | 29 | } |
20 | 30 |
|
21 | | - # If you don't find the filename in the static files |
22 | | - # Then request it from the unicorn server |
23 | | - if (!-f $request_filename) { |
24 | | - proxy_pass http://unicorn_jiffyshirts; |
25 | | - break; |
26 | | - } |
| 31 | + <%= @out[:extra_config] %> |
27 | 32 | } |
| 33 | +<% end %> |
28 | 34 |
|
29 | | - <%= @out[:extra_config] %> |
30 | | -} |
31 | | - |
32 | | -<% regex = node.read('nginx_custom', 'mobile_api_paths_regex') %> |
33 | | -<% (node.read('nginx_custom', 'mobile_app_additional_hostnames') || []).each do |name| %> |
34 | | - <% next if regex.blank? %> |
| 35 | +<% host_redirects.each do |main_hostname, mobile_app_additional_hostnames| %> |
| 36 | + <% mobile_app_additional_hostnames.each do |name| %> |
| 37 | + <% next if regex.blank? %> |
35 | 38 |
|
36 | | - server { |
37 | | - server_name <%= name %>; |
| 39 | + server { |
| 40 | + server_name <%= name %>; |
38 | 41 |
|
39 | | - include /srv/www/jiffyshirts/current/config/nginx/server_common.conf; |
| 42 | + include /srv/www/jiffyshirts/current/config/nginx/server_common.conf; |
40 | 43 |
|
41 | | - # allow to process mobile app requests if they made to additional domain |
42 | | - location ~ <%= regex %> { |
43 | | - proxy_pass http://unicorn_jiffyshirts; |
44 | | - } |
| 44 | + # allow to process mobile app requests if they made to additional domain |
| 45 | + location ~ <%= regex %> { |
| 46 | + proxy_pass http://unicorn_jiffyshirts; |
| 47 | + } |
45 | 48 |
|
46 | | - # redirect all the other requests to main domain |
47 | | - location / { |
48 | | - return 301 $scheme://<%= main_hostname %>$request_uri; |
| 49 | + # redirect all the other requests to main domain |
| 50 | + location / { |
| 51 | + return 301 $scheme://<%= main_hostname %>$request_uri; |
| 52 | + } |
49 | 53 | } |
50 | | - } |
| 54 | + <% end %> |
51 | 55 | <% end %> |
52 | 56 |
|
0 commit comments