Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Send typical proxy headers #33

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/config/lib/nginx_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class NginxConfig
encoding: "UTF-8",
clean_urls: false,
https_only: false,
worker_connections: 512
worker_connections: 512,
headers: []
}

def initialize(json_file)
Expand All @@ -29,6 +30,7 @@ def initialize(json_file)
json["proxies"][loc]["path"] = uri.path
uri.path = ""
json["proxies"][loc]["host"] = uri.to_s
json["proxies"][loc]["headers"] = hash["headers"] || DEFAULT[:headers]
end
json["clean_urls"] ||= DEFAULT[:clean_urls]
json["https_only"] ||= DEFAULT[:https_only]
Expand Down
16 changes: 16 additions & 0 deletions scripts/config/templates/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ http {
<% proxies.each do |location, hash| %>
location <%= location %> {
proxy_pass <%= hash['origin'] %>;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $proxy_host;
<% if hash['headers'].any? { |s| s.casecmp('x-forwarded-proto') == 0 } %>
proxy_set_header X-Forwarded-Proto $scheme;
<% end %>
<% if hash['headers'].any? { |s| s.casecmp('x-forwarded-for') == 0 } %>
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
<% end %>
<% if hash['headers'].any? { |s| s.casecmp('x-forwarded-port') == 0 } %>
proxy_set_header X-Forwarded-Port $server_port;
<% end %>
<% if hash['headers'].any? { |s| s.casecmp('x-request-start') == 0 } %>
proxy_set_header X-Request-Start "t=$msec";
<% end %>
}
<% end %>

Expand Down