Skip to content

Commit 3285c10

Browse files
committed
add dedicated first-hop forwarder virtual server
1. We need to retain certain functionality to serve on primary_host 2. However, function URL cannot configure custom domain name 3. Add $JUMP_HOST to serve as a first-hop forwarder, identical to `location /` on PRIMARY_HOST, but host no other functions
1 parent 8e8b8f4 commit 3285c10

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

config/nginx.conf.erb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<% primary_host = ENV.fetch('PRIMARY_HOST', 'rko-router.invalid') %>
2+
<% jump_host = ENV.fetch('JUMP_HOST', 'jump.rko-router.invalid') %>
23
<% platform = ENV.fetch("RKO_ROUTER_PLATFORM", "heroku") %>
34
<% current_year = '2026' %>
45

@@ -128,6 +129,42 @@ http {
128129
}
129130
}
130131

132+
server {
133+
listen <%= ENV.fetch("PORT") %>;
134+
server_name <%= jump_host %>;
135+
136+
default_type text/plain;
137+
138+
location = /healthz {
139+
return 200 "<%= primary_host %> (jump)\n";
140+
}
141+
142+
location / {
143+
if ( $http_x_rko_host = "" ) {
144+
return 404 "<%= primary_host %> (jump, no x-rko-host)\n";
145+
}
146+
if ( $http_x_rko_host = $http_host ) {
147+
return 404 "<%= primary_host %> (jump, x-rko-host as jump)\n";
148+
}
149+
if ( $http_x_rko_forwarded = "yes" ) {
150+
return 500 "<%= primary_host %> (jump, loop)\n";
151+
}
152+
153+
set $x_rko_xfp "$http_x_rko_xfp";
154+
if ( $x_rko_xfp = "" ) {
155+
set $x_rko_xfp "$http_x_forwarded_proto";
156+
}
157+
if ( $x_rko_xfp = "" ) {
158+
set $x_rko_xfp "http";
159+
}
160+
161+
proxy_set_header Host $http_x_rko_host;
162+
proxy_set_header X-Forwarded-Proto $x_rko_xfp;
163+
proxy_set_header x-rko-forwarded "yes";
164+
proxy_pass http://localhost:<%= ENV.fetch("PORT") %>;
165+
}
166+
}
167+
131168
server {
132169
listen <%= ENV.fetch("PORT") %>;
133170
server_name regional.rubykaigi.org;

0 commit comments

Comments
 (0)