Serving otree over HTTPS

330 views
Skip to first unread message

Guillaume Denis

unread,
Apr 30, 2021, 8:49:30 AM4/30/21
to oTree help & discussion
Hello,

I am trying to host otree on a Linux Server and serve it with https behind nginx.

As an aside: if anyone encounters a uvicorn error "Unsupported upgrade request.", it's fixed by installing uvicon[standard] (more info here):
pip3 uninstall -y uvicorn
pip3 install uvicorn[standard]

Back to the problem I run into: now I have a working nginx+Let's encrypt+otree setup, except for the fact that some links and redirects include hardcoded "http://" URLs rather than "https://" and then the navigation is broken. For instance, let's say my server is reachable at https://otreedemo.net
Is there a way to configure/force https or is this a bug in otree-core?

Many thanks,
Guillaume

Guillaume Denis

unread,
Apr 30, 2021, 9:15:01 AM4/30/21
to oTree help & discussion
I am not sure but it could be related to request.url_for:

How uvicorn is configured:

...and how it's supposed to be run behind nginx:

Incidentally it may be interesting to be able to pass uvicorn custom configuration settings from oTree (or maybe with environment variables)

Thanks, Guillaume

Guillaume Denis

unread,
Apr 30, 2021, 9:59:41 AM4/30/21
to oTree help & discussion
Sorry for multi-posting, I have found a solution by setting the environment variable:
FORWARDED_ALLOW_IPS="*"

(* disable checking of Front-end IPs, see https://docs.gunicorn.org/en/stable/settings.html, * may not be the appropriate solution for every case)

Nevertheless, I still think it could be interesting to set uvicorn options (for instance specifying certificates https://www.uvicorn.org/deployment/#running-with-https) from oTree, and thus be able to tweak the config here:

Guillaume
Reply all
Reply to author
Forward
0 new messages