Question

How do I get a SSL certificate for my WSGI Flask server so it can send data over HTTPS?

Posted March 11, 2020 141 views
NginxPython

I am running a site https://coderjobmarket.com on a DigitalOcean droplet using Ubuntu 18.04 and Nginx 1.14.0. I also intend to have a Flask app using WSGI as its production server.

It would be enough to use HTTP with this server, except for a problem I have with my site: Namely, my site sends a query to the Flask server, and the browser demands the response be in HTTPS, or else it gives a “Mixed Content” error (receiving HTTP on a HTTPS site) and blocks the Flask server’s response.

The specific error message I get from my browser is this:

“Mixed Content: The page at ’https://coderjobmarket.com/results’ was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ’http://165.227.78.120:5000/lang/vue/loc/Vancouver’. This request has been blocked; the content must be served over HTTPS.”

My question is, how can I get a SSL certificate for my Flask server so it can send data over HTTPS?

My second question is, if I use a self signed SSL certificate, will the page give me one of these warnings when it tries to load the response from the Flask server? One of these:

https://assets.digitalocean.com/articles/nginx_ssl_1604/self_signed_warning.png (Big red padlock, and the message in h1 tags, “Your connection is not private”)

If the answer is “yes, it will give every user a warning that their connection is not private,” then the Self Signed SSL Certificate option does not work for me.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there @plutownium,

You could follow the steps from this tutorial here on how to use Nginx as a reverse proxy with uWSGI:

https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04#step-7-%E2%80%94-securing-the-application

You could take a look at steps 6 and 7 on how to configuring Nginx to proxy requests and how to secure it with Let’s Encrypt.

Hope that this helps!
Regards,
Bobby

by Justin Ellingwood
by Kathleen Juell
In this guide, we will be setting up a simple Python application using the Flask microframework on Ubuntu 18.04. The bulk of this article will be about how to set up the uWSGI application server to launch the application and how to configure Nginx to act as a front-end reverse proxy.
Submit an Answer