Skip to content

Commit 486a9df

Browse files
authored
Merge pull request #23 from sdtechdev/adding-multiple-domain
Add multiple domain to same upstream
2 parents 71aff3a + eb4e074 commit 486a9df

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed
+39-35
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
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') %>
23

34
upstream <%= @name %>_<%= @application[:domains].first %> {
45
server unix:<%= @deploy_dir.to_s %>/shared/sockets/<%= @name %>.sock fail_timeout=0;
56
}
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 %>;
611

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;
1613

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+
}
1929
}
2030

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] %>
2732
}
33+
<% end %>
2834

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? %>
3538

36-
server {
37-
server_name <%= name %>;
39+
server {
40+
server_name <%= name %>;
3841

39-
include /srv/www/jiffyshirts/current/config/nginx/server_common.conf;
42+
include /srv/www/jiffyshirts/current/config/nginx/server_common.conf;
4043

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+
}
4548

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+
}
4953
}
50-
}
54+
<% end %>
5155
<% end %>
5256

0 commit comments

Comments
 (0)