Skip to content

FIX: Ngnix fails to start if custom ___location upstream is unavailable/unreachable #2672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
32 changes: 30 additions & 2 deletions backend/templates/_location.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
___location {{ path }} {
set $forward_scheme {{ forward_scheme }};
set $forward_host {{ forward_host }};
set $forward_port {{ forward_port }};

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass {{ forward_scheme }}://{{ forward_host }}:{{ forward_port }}{{ forward_path }};

{% assign location_path_end_char = path | slice: -1 %}
{% assign forward_path_end_char = forward_path | slice: -1 %}
{% if location_path_end_char == "/" and forward_path_end_char != "/" %}
if ($request_uri ~ "{{ path }}(.*$)") {
# Location path ends with / so the regex match will exclude that slash from the match,
# but forward path doesn't, so we must prefix $path_remainder with a slash.
set $uri_remainder /$1;
}
{% elsif location_path_end_char != "/" and forward_path_end_char == "/" %}
# Location path does not have a trailing / but forward path does,
# so we make sure to capture $uri_remainder without a leading slash.
if ($request_uri ~ "{{ path }}/(.*$)") {
set $uri_remainder $1;
}
{% else %}
# Either both ___location path and forward path have a trailing /, or neither do.
# If both do, then we need to capture $uri_remainder without a leading /, but if neither do,
# then we need to capture $uri_remainder with a leading slash (if it has one - it could just be some GET parameters).
# The code for both scenarios happens to be the same.
if ($request_uri ~ "{{ path }}(.*$)") {
set $uri_remainder $1;
}
{% endif %}

proxy_pass $forward_scheme://$forward_host:$forward_port{{ forward_path }}$uri_remainder;

{% include "_access.conf" %}
{% include "_assets.conf" %}
Expand All @@ -18,7 +47,6 @@
proxy_http_version 1.1;
{% endif %}


{{ advanced_config }}
}

6 changes: 6 additions & 0 deletions frontend/js/app/nginx/proxy/___location-item.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
</div>
<div class="row config">
<div class="col-md-12">
<p><%- i18n('all-hosts', 'advanced-config-var-headline') %></p>
<ul class="text-monospace">
<li><code>$forward_scheme</code> <%- i18n('proxy-hosts', 'forward-scheme') %></li>
<li><code>$forward_host</code> <%- i18n('proxy-hosts', 'forward-host') %></li>
<li><code>$forward_port</code> <%- i18n('proxy-hosts', 'forward-port') %></li>
</ul>
<div class="form-group">
<textarea name="advanced_config" rows="8" class="form-control text-monospace model" placeholder="# <%- i18n('all-hosts', 'advanced-warning') %>"><%- advanced_config %></textarea>
</div>
Expand Down