question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redirects change https requests to http locations

See original GitHub issue

I’m running Caravel in AWS with this configuration:

  • ELB terminates SSL (and accepts only https requests)
  • Docker container runs gunicorn + caravel

Many requests hang in the browser because the https request is redirected to a http location.

$ curl -Ik https://caravel.example.com/
HTTP/1.1 302 FOUND
Content-Length: 239
Content-Type: text/html; charset=utf-8
Date: Thu, 18 Aug 2016 16:30:20 GMT
Location: http://caravel.example.com/caravel/welcome
Server: gunicorn/19.6.0
Connection: keep-alive

I’m not sure if this is an issue with Caravel or upstream in Flask or Flask-AppBuilder.

I tried setting PREFERRED_URL_SCHEME = 'https' in caravel_config.py hoping that would propagate to flask, but either it did not propagate, or it had no effect. (That config instructs flask what scheme to use when it cannot be determined.)

I think the right way to deal with this is to determine the protocol from the ‘X-Forwarded-Proto’ header. But I’m not sure if this is a bug in Caravel or Flask.

thanks, Dennis

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
nowak-ninjacommented, May 2, 2019

Hey, I think redirects on ALB/Nginx level from 80 to 443 is a workaround, not a solution. I am not familiar with flask/gunicorn/whatever runs the Superset and anyway tried to force redirects go to https rather than http, but without success. I ended up with redirect solution on ALB, JUST for Superset. Is there ANY other way to force Superset to use https? Middleware or something?

7reactions
dennisobriencommented, Aug 25, 2016

For the record, I found the cause of the problem and the fix. When gunicorn is run on a different machine from the load balancer (nginx or ELB), it needs to be told explicitly to trust the X-Forwarded-* headers sent. gunicorn takes an option --forwarded-allow-ips which can either be a comma separated list of ip addresses, or “*” to trust all.

I’m starting caravel with this command (with gunicorn running behind an ELB):

gunicorn \
  --error-logfile - \
  --access-logfile - \
  -w 8 \
  -k gevent \
  -b 0.0.0.0:8080 \
  --timeout 120 \
  --limit-request-line 0 \
  --limit-request-field_size 0 \
  --forwarded-allow-ips="*" \
  caravel:app

More details are in the gunicorn docs: http://docs.gunicorn.org/en/stable/deploy.html

cheers, Dennis

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirects with HTTPS - DNSimple Blog
Understanding how to properly redirects with HTTP and HTTPS sites.
Read more >
Redirections in HTTP - MDN Web Docs - Mozilla
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that ...
Read more >
How to Redirect HTTP to HTTPS - Semrush
This guide will take a deep dive into redirecting from HTTP to HTTPS. We'll look at what HTTP and HTTPS are, why redirects...
Read more >
How to Redirect Website from HTTP to HTTPS? - Geekflare
Go to Page Rules · Click “Create Page Rule” · Enter the URL (put the asterisk, so redirection happens for all the URI)...
Read more >
In Nginx, how can I rewrite all http requests to https while ...
In the simplest case your host will be fixed to be your service you want to send them to - this will do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found