Commit 18996fe0 authored by Damien Mathieu's avatar Damien Mathieu

add option to redirect all http traffic to https

parent abde0ba6
...@@ -78,6 +78,16 @@ You can replace the default nginx 404 and 500 error pages by defining the path t ...@@ -78,6 +78,16 @@ You can replace the default nginx 404 and 500 error pages by defining the path t
} }
``` ```
#### HTTPS Only
You can redirect all HTTP requests to HTTPS.
```
{
"https_only": true
}
```
#### Proxy Backends #### Proxy Backends
For single page web applications like Ember, it's common to back the application with another app that's hosted on Heroku. The down side of separating out these two applications is that now you have to deal with CORS. To get around this (but at the cost of some latency) you can have the static buildpack proxy apps to your backend at a mountpoint. For instance, we can have all the api requests live at `/api/` which actually are just requests to our API server. For single page web applications like Ember, it's common to back the application with another app that's hosted on Heroku. The down side of separating out these two applications is that now you have to deal with CORS. To get around this (but at the cost of some latency) you can have the static buildpack proxy apps to your backend at a mountpoint. For instance, we can have all the api requests live at `/api/` which actually are just requests to our API server.
......
...@@ -15,6 +15,7 @@ class NginxConfig ...@@ -15,6 +15,7 @@ class NginxConfig
end end
end end
json["clean_urls"] ||= false json["clean_urls"] ||= false
json["https_only"] ||= false
json["routes"] ||= {} json["routes"] ||= {}
json["routes"] = Hash[json["routes"].map {|route, target| [NginxConfigUtil.to_regex(route), target] }] json["routes"] = Hash[json["routes"].map {|route, target| [NginxConfigUtil.to_regex(route), target] }]
json["redirects"] ||= {} json["redirects"] ||= {}
......
...@@ -46,6 +46,12 @@ http { ...@@ -46,6 +46,12 @@ http {
} }
<% end %> <% end %>
<% if https_only %>
if ($http_x_forwarded_proto != "https") {
return 301 https://$host$uri;
}
<% end %>
<% redirects.each do |path, hash| %> <% redirects.each do |path, hash| %>
location <%= path %> { location <%= path %> {
return <%= hash['status'] || 301 %> <%= hash['url'] %>; return <%= hash['status'] || 301 %> <%= hash['url'] %>;
......
...@@ -72,6 +72,16 @@ RSpec.describe "Simple" do ...@@ -72,6 +72,16 @@ RSpec.describe "Simple" do
end end
end end
describe "https only" do
let(:name) { "https_only" }
it "should redirect http to https" do
response = app.get("/foo")
expect(response.code).to eq("301")
expect(response['location']).to eq("https://#{AppRunner::HOST_IP}/foo")
end
end
describe "custom error pages" do describe "custom error pages" do
let(:name) { "custom_error_pages" } let(:name) { "custom_error_pages" }
......
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