Skip to content

Commit ec6c027

Browse files
committed
Merge pull request openedx-unsupported#2689 from edx/arbab/fix-nginx-with-elif
use the elif instead of second if statement
2 parents c26d559 + 50ad163 commit ec6c027

File tree

10 files changed

+40
-30
lines changed

10 files changed

+40
-30
lines changed

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/analytics_api.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ server {
1616
{
1717
set $do_redirect_to_https "true";
1818
}
19-
{% endif %}
20-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
19+
20+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
2121

2222
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
2323
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/cms.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ error_page {{ k }} {{ v }};
5151
{
5252
set $do_redirect_to_https "true";
5353
}
54-
{% endif %}
55-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
54+
55+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
5656

5757
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
5858
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/credentials.j2

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,29 @@ location @proxy_to_app {
5252
proxy_redirect off;
5353
proxy_pass http://credentials_app_server;
5454
}
55-
{% if NGINX_SET_X_FORWARDED_HEADERS %}
56-
if ($scheme != "https") {
57-
rewrite ^ https://$host$uri permanent;
58-
}
59-
{% else %}
60-
# Forward to HTTPS if we're an HTTP request...
61-
if ($http_x_forwarded_proto = "http") {
62-
set $do_redirect "true";
55+
# Nginx does not support nested condition or or conditions so
56+
# there is an unfortunate mix of conditonals here.
57+
{% if NGINX_REDIRECT_TO_HTTPS %}
58+
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "scheme" %}
59+
# Redirect http to https over single instance
60+
if ($scheme != "https")
61+
{
62+
set $do_redirect_to_https "true";
6363
}
64+
65+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
6466

65-
# Run our actual redirect...
66-
if ($do_redirect = "true") {
67-
rewrite ^ https://$host$request_uri? permanent;
67+
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
68+
if ($http_x_forwarded_proto = "http")
69+
{
70+
set $do_redirect_to_https "true";
6871
}
69-
{% endif %}
72+
{% endif %}
73+
74+
# Execute the actual redirect
75+
if ($do_redirect_to_https = "true")
76+
{
77+
rewrite ^ https://$host$request_uri? permanent;
78+
}
79+
{% endif %}
7080
}

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/ecommerce.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ server {
3939
{
4040
set $do_redirect_to_https "true";
4141
}
42-
{% endif %}
43-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
42+
43+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
4444
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
4545
if ($http_x_forwarded_proto = "http")
4646
{

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/edx_notes_api.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ server {
1616
{
1717
set $do_redirect_to_https "true";
1818
}
19-
{% endif %}
20-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
19+
20+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
2121

2222
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
2323
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/insights.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ location @proxy_to_app {
4242
{
4343
set $do_redirect_to_https "true";
4444
}
45-
{% endif %}
46-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
45+
46+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
4747

4848
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
4949
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/kibana.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ server {
3232
{
3333
set $do_redirect_to_https "true";
3434
}
35-
{% endif %}
36-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
35+
36+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
3737

3838
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
3939
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/lms-preview.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ server {
8585
{
8686
set $do_redirect_to_https "true";
8787
}
88-
{% endif %}
89-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
88+
89+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
9090

9191
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
9292
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/lms.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ error_page {{ k }} {{ v }};
7171
{
7272
set $do_redirect_to_https "true";
7373
}
74-
{% endif %}
75-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
74+
75+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
7676

7777
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
7878
if ($http_x_forwarded_proto = "http")

playbooks/roles/nginx/templates/edx/app/nginx/sites-available/programs.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ server {
4040
{
4141
set $do_redirect_to_https "true";
4242
}
43-
{% endif %}
44-
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
43+
44+
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
4545

4646
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB
4747
if ($http_x_forwarded_proto = "http")

0 commit comments

Comments
 (0)