Skip to content

Commit

Permalink
fix: forward protocol correctly from reverse proxy (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored Nov 13, 2023
1 parent 4b263f1 commit eca77f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ http {

include /etc/nginx/conf.d/features.conf;

# use the scheme from the X-Forwarded-Proto header if present or default to $scheme
map $http_x_forwarded_proto $thescheme {
default $http_x_forwarded_proto;
'' $scheme;
}

include /etc/nginx/conf.d/multi-channel.conf;
}
6 changes: 3 additions & 3 deletions nginx/templates/multi-channel.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Proto $thescheme;

add_header X-Cache-Status $upstream_cache_status;
proxy_ignore_headers Cache-Control;
Expand Down Expand Up @@ -135,7 +135,7 @@ server {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Proto $thescheme;

proxy_no_cache true;
proxy_cache_bypass true;
Expand All @@ -155,7 +155,7 @@ server {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Proto $thescheme;

proxy_ignore_headers Cache-Control;
proxy_cache_valid 200 302 {{ getenv "CACHE_DURATION_NGINX_OK" }};
Expand Down
4 changes: 4 additions & 0 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ export function app() {

console.log('ICM_BASE_URL is', ICM_BASE_URL);

// running behind nginx - make sure to use all x-forwarded headers correctly
// see https://expressjs.com/en/guide/behind-proxies.html
server.set('trust proxy', true);

return server;
}

Expand Down

0 comments on commit eca77f9

Please sign in to comment.