2

I have a flask app running on an apache HTTP server on ubuntu 14.04. Everything works great, but I'm now trying to make things secure and get HTTPS up and running. The content still renders properly when requesting the HTTP URLs, but static CSS files are not loading when changing the prefix to HTTPS.

Some useful details and previous attempts:

  • I have the CSS files in the usual static/css location.
  • This answer was helpful, and got javascript rendering properly, but using AddType for CSS isn't working for some reason.
  • I tried sudo a2enmod mime to make sure that Apache module was enabled, and it was.
  • I tried forcing the type for css (similar to what was suggested here, but with css instead of js and javascript), but that didn't work either.
  • I've tried adding the AddType declaration to my configuration file located in /etc/apache/sites-available/FlaskApp.conf (that's where the successful AddType text/javascript .js declaration is located), and I've also tried putting the AddType declaration in a .htaccess file located in the root directory of my FlaskApp, but both attempts were unsuccessful.

Everything loads fine when accessing the site with the http:// prefix, just not the https:// prefix. I've tried accessing it from Chrome and Firefox.

Chrome Response

Looking at the console when loading the page in Chrome is shows the following for all CSS files:

Resource interpreted as Stylesheet but transferred with MIME type application/x-gzip

Looking at the network tab, everything looks similar between the http request and the https request, except that the https request is completely missing the Response Headers section.

When attempting to load just the /static/css/styles.css file in Chrome, it attempts to download the file instead of displaying it in the browser.

Firefox Response

When attempting to load just the /static/css/styles.css file in Firefox, it loads in the browser. However, it's not ascii text but rather jumbled characters as though it's loading a binary file. Here's the console error message in Firefox:

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.

So my question is, how do I get my HTTPS/Flask/Apache/Ubuntu setup to properly return static css files so that my pages render properly?

This suggestion and this suggestion look promising, but I'm not sure how to make it so that any request that hits /static/css/*.css returns the proper css file with the "Content Type" or "mimetype" set correctly.

Community
  • 1
  • 1
mgig
  • 2,395
  • 4
  • 21
  • 36

0 Answers0