Move nginx directives inside location block
Being outside caused an unintended interaction between "pushstate" and a doubly nested location block
@@ -79,6 +79,20 @@ http {
root <%= ENV["APP_ROOT"] %>/public;
+ {{if .ForceHTTPS}}
+ if ($http_x_forwarded_proto != "https") {
+ return 301 https://$host$request_uri;
+ }
+ {{else}}
+ <% if ENV["FORCE_HTTPS"] %>
+ if ($http_x_forwarded_proto != "https") {
+ return 301 https://$host$request_uri;
+ }
+ <% end %>
+ {{end}}
+
+
+ location / {
{{if .PushState}}
if (!-e $request_filename) {
rewrite ^(.*)$ / break;
@@ -96,18 +110,6 @@ http {
auth_basic_user_file <%= ENV["APP_ROOT"] %>/nginx/conf/.htpasswd;
{{end}}
- {{if .ForceHTTPS}}
- if ($http_x_forwarded_proto != "https") {
- return 301 https://$host$request_uri;
- }
- {{else}}
- <% if ENV["FORCE_HTTPS"] %>
- if ($http_x_forwarded_proto != "https") {
- return 301 https://$host$request_uri;
- }
- <% end %>
- {{end}}
-
{{if .SSI}}
ssi on;
{{end}}
@@ -116,18 +118,17 @@ http {
add_header Strict-Transport-Security "max-age=31536000{{if .HSTSIncludeSubDomains}}; includeSubDomains{{end}}{{if .HSTSPreload}}; preload{{end}}";
{{end}}
+ {{if ne .LocationInclude ""}}
+ include {{.LocationInclude}};
+ {{end}}
+ }
+
{{if not .HostDotFiles}}
location ~ /\. {
deny all;
return 404;
}
{{end}}
-
- {{if ne .LocationInclude ""}}
- location / {
- include {{.LocationInclude}};
- }
- {{end}}
}
}
`
