Skip to content

Commit 468b700

Browse files
committed
Additional fixes to proxy/redirect handling
1 parent 2b497f6 commit 468b700

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

appyter/profiles/default/templates/production/nginx.conf.j2

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,26 @@ http {
8080
{%- endwith %}
8181
{%- endif %}
8282

83+
84+
{%- if _config.PROXY %}
85+
map $http_x_forwarded_for_proto $proxied_proto {
86+
default $http_x_forwarded_for_proto;
87+
'' "http";
88+
}
89+
map $http_x_forwarded_host $proxied_host {
90+
default $http_x_forwarded_host;
91+
'' $http_host;
92+
}
93+
{%- endif %}
94+
8395
server {
8496
listen {{ _config.PORT }};
8597
server_name {{ _config.HOST }};
8698
include /etc/nginx/mime.types;
8799
charset utf-8;
88100
sendfile on;
89101
keepalive_timeout 0;
102+
absolute_redirect off;
90103

91104
set $parsed_method "${request_method}:${http_accept}";
92105

@@ -125,7 +138,7 @@ http {
125138

126139
location ~ ^{{ join_routes(_config.PREFIX, '[^/]+') }}$ {
127140
{% if _config.PROXY %}
128-
rewrite ^(.*)$ $http_x_forwarded_proto://$http_x_forwarded_host:$http_x_forwarded_port$1/ redirect;
141+
rewrite ^(.*)$ $proxied_proto://$proxied_host$1/ redirect;
129142
{% else %}
130143
rewrite ^(.*)$ $1/ redirect;
131144
{% endif %}
@@ -192,7 +205,7 @@ http {
192205
{%- if _config.PREFIX != '/' %}
193206
location / {
194207
{%- if _config.PROXY %}
195-
rewrite ^/?(.*)$ $http_x_forwarded_proto://$http_x_forwarded_host:$http_x_forwarded_port{{ _config.PREFIX }}$1 redirect;
208+
rewrite ^/?(.*)$ $proxied_proto://$proxied_host{{ _config.PREFIX }}$1 redirect;
196209
{% else %}
197210
rewrite ^/?(.*)$ {{ _config.PREFIX }}$1 redirect;
198211
{%- endif %}

0 commit comments

Comments
 (0)