0

I have a web-page hosted in S3 bucket, and it is setup for HTTPS.

My back-end runs on an AWS Lightsail instance with a static IP address that my front-end makes requests to to get JSON data. The server is a Python Flask server that is running within a Docker container.

When I run docker run -p 443:MY_PORT ... (port 443 is Lightsail's HTTPS port) I cannot get my front-end to communicate with the server. Instead I get this error:

spread.js:25 Mixed Content: The page at 'https://www.bible-it.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint ... This request has been blocked; the content must be served over HTTPS.

There are no problems, if I run my docker command through port 80.

What is the best way to setup HTTPS for my Lightsail instance?

Also if my setup of

FRONTEND: s3 Bucket

BACKEND: Lightsail > Ubuntu > Docker > Python Flask

is a bad setup please let me know. I am self taught and would love some guidance. Thank you so much.

Elisabeth Strunk
  • 516
  • 1
  • 6
  • 15
Ricardo Carballo
  • 125
  • 1
  • 10

1 Answers1

0

Like the error message says, your server does not serve the content properly over HTTPS. This could have several reasons:

  • Your requests are redirected to HTTP. Make sure that your server does not do that.
  • Your Lightsail instance does not allow HTTPS connections. In this case you have to update your instance's firewall.
  • Your TLS/SSL certificate is not set up properly. In this case you can use e.g. Let's Encrypt and follow their documentation for a proper setup.


One last tip:

If I understand you correctly, you are running your application on the development server. This is the case, if you run your Flask application with

from Flask import Flask
app = Flask(__name__)
app.run()

In general, you should not use the development server in production.

It is not designed to be particularly efficient, stable, or secure. It does not support all the possible features of a HTTP server.

You can read more about this in this discussion.

Elisabeth Strunk
  • 516
  • 1
  • 6
  • 15
  • Thank you I will try your suggestions, the update to firewall looks promising. I will update shortly. – Ricardo Carballo Apr 27 '20 at 23:34
  • Quick question. In the /var/www/item_catalog/item_catalog.wsgi the commands: ```import sys import logging logging.basicConfig(stream=sys.stderr) sys.path.insert(0,"/var/www/item_catalog/item_catalog") from app import app as application``` is the last line saying ** from the directory app import the flask object app as application***? – Ricardo Carballo Apr 29 '20 at 16:29
  • Yes, exactly! Are you deploying your app with WSGI now? – Elisabeth Strunk Apr 29 '20 at 18:55
  • Thank you I was able to get everything working properly. This was an amazing resource, I will keep this, I really learn alot. – Ricardo Carballo Apr 29 '20 at 22:23
  • 1
    So glad to hear that my notes were helpful to you :) – Elisabeth Strunk Apr 30 '20 at 19:15