3

How can I enable HTTPS for a DASH aplication running on a webserver with Python?

I already have a SSL certificate (.key and .crt)

NicolasZ
  • 845
  • 4
  • 10
  • 26

1 Answers1

6

If dash is the web server handling the routing (instead of Apache or Nginx), in your index.py file, on the part where you initiate the server, put the following code (replace local.crt and local.key with the absolute or relative path of your certificates):

if __name__ == "__main__":
    context = ('local.crt','local.key')
    app.run_server(host="192.168.200.172", port="8050", debug=True, ssl_context=context)

The address and the port is whatever you have on your server

or with the run method

app.run(debug=True, ssl_context=context)

If, Nginx or apache is handling the reverse proxy, meaning, it receives the request from the client and then directs it to different apps, Dash for example, then you need to configure the SSL certificate in that server, and then it will redirect a http petition to the Dash, but it will be shown to the user as a Https.

NicolasZ
  • 845
  • 4
  • 10
  • 26
  • Hello, I need your second idea. My dash app will be called from a server (another website). How should we configure the server to redirect an HTTP petition to my Dash app? – Mohammad Nov 16 '22 at 16:13
  • It shouldn't be complicated. It is a matter of configuring the other server (for example NGINX) to redirect a request in whatever URL, to the dash address and port. Here is an example of how to do it on NGINX https://www.hostinger.com/tutorials/nginx-redirect/#Redirection_in_Nginx – NicolasZ Nov 17 '22 at 15:06