Commit ec6c027b by Arbab Nazar

Merge pull request #2689 from edx/arbab/fix-nginx-with-elif

use the elif instead of second if statement
parents c26d5597 50ad163b
...@@ -16,8 +16,8 @@ server { ...@@ -16,8 +16,8 @@ server {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -51,8 +51,8 @@ error_page {{ k }} {{ v }}; ...@@ -51,8 +51,8 @@ error_page {{ k }} {{ v }};
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -52,19 +52,29 @@ location @proxy_to_app { ...@@ -52,19 +52,29 @@ location @proxy_to_app {
proxy_redirect off; proxy_redirect off;
proxy_pass http://credentials_app_server; proxy_pass http://credentials_app_server;
} }
{% if NGINX_SET_X_FORWARDED_HEADERS %} # Nginx does not support nested condition or or conditions so
if ($scheme != "https") { # there is an unfortunate mix of conditonals here.
rewrite ^ https://$host$uri permanent; {% if NGINX_REDIRECT_TO_HTTPS %}
} {% if NGINX_HTTPS_REDIRECT_STRATEGY == "scheme" %}
{% else %} # Redirect http to https over single instance
# Forward to HTTPS if we're an HTTP request... if ($scheme != "https")
if ($http_x_forwarded_proto = "http") { {
set $do_redirect "true"; set $do_redirect_to_https "true";
} }
{% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Run our actual redirect... # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($do_redirect = "true") { if ($http_x_forwarded_proto = "http")
rewrite ^ https://$host$request_uri? permanent; {
set $do_redirect_to_https "true";
} }
{% endif %} {% endif %}
# Execute the actual redirect
if ($do_redirect_to_https = "true")
{
rewrite ^ https://$host$request_uri? permanent;
}
{% endif %}
} }
...@@ -39,8 +39,8 @@ server { ...@@ -39,8 +39,8 @@ server {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
{ {
......
...@@ -16,8 +16,8 @@ server { ...@@ -16,8 +16,8 @@ server {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -42,8 +42,8 @@ location @proxy_to_app { ...@@ -42,8 +42,8 @@ location @proxy_to_app {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -32,8 +32,8 @@ server { ...@@ -32,8 +32,8 @@ server {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -85,8 +85,8 @@ server { ...@@ -85,8 +85,8 @@ server {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -71,8 +71,8 @@ error_page {{ k }} {{ v }}; ...@@ -71,8 +71,8 @@ error_page {{ k }} {{ v }};
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
...@@ -40,8 +40,8 @@ server { ...@@ -40,8 +40,8 @@ server {
{ {
set $do_redirect_to_https "true"; set $do_redirect_to_https "true";
} }
{% endif %}
{% if NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %} {% elif NGINX_HTTPS_REDIRECT_STRATEGY == "forward_for_proto" %}
# Forward to HTTPS if we're an HTTP request... and the server is behind ELB # Forward to HTTPS if we're an HTTP request... and the server is behind ELB
if ($http_x_forwarded_proto = "http") if ($http_x_forwarded_proto = "http")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment