Git Product home page Git Product logo

Comments (7)

adamchainz avatar adamchainz commented on August 15, 2024

Hi, I believe I've encountered a bug or not followed the instructions correctly. Most likely, the latter. But my issue is that after following the instructions for configuring Cloudfront with whitenoise, CF cannot access any files under my static folder.

Error: The requested resource was not found on this server.

This is too little information to go on. What are the requests you're making and how are they failing?

Have you tried accessing your app not through the CDN?

Also, the instructions have us create staticfiles and static directories, is that supposed to be the case when using a CDN? Or was staticfiles only for setup without a CDN? Should these two directories be consolidated?

You need the directories whether or not you are using a CDN.

from whitenoise.

dorian-adams avatar dorian-adams commented on August 15, 2024

Hi, I believe I've encountered a bug or not followed the instructions correctly. Most likely, the latter. But my issue is that after following the instructions for configuring Cloudfront with whitenoise, CF cannot access any files under my static folder.
Error: The requested resource was not found on this server.

This is too little information to go on. What are the requests you're making and how are they failing?

All requests to static files fail with a 404 error Not Found: The requested resource was not found on this server. This includes my css, js, and static image files. When loading a page, the necessary static resources fail with that error. The same error also occurs when accessing the files directly from the CDN.

Initially, I began with: "whitenoise.storage.CompressedManifestStaticFilesStorage" - which didn't work at all. It caused a server error. So I then switched to "whitenoise.storage.CompressedStaticFilesStorage" and now pages will load but without any of my static content.

So I wonder if there's some cache issue going on? Essentially my CDN can load everything on my site except the files being handled by whitenoise.storage.

Have you tried accessing your app not through the CDN?

Serving the files locally in debug works if I run python manage.py runserver --nostatic but standard python manage.py runserver leads to the same 404s on static files.

from whitenoise.

adamchainz avatar adamchainz commented on August 15, 2024

Are you using {% static %} to generate your static URL’s? What do they look like?

from whitenoise.

dorian-adams avatar dorian-adams commented on August 15, 2024

Are you using {% static %} to generate your static URL’s? What do they look like?

Yes, here are a few of them:

<link rel="icon" href="{% static 'img/brand/favicon.png' %}" type="image/png">
<link rel="stylesheet" href="{% static 'libs/@fortawesome/fontawesome-free/css/all.min.css' %}">
<link rel="stylesheet" href="{% static 'css/quick-website.css' %}" id="stylesheet">

Would HTTPS or HSTS settings conflict with anything within whitenoise?

SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True

# HSTS Settings
SECURE_HSTS_SECONDS = 31536000  # 1 year
SECURE_HSTS_PRELOAD = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True

from whitenoise.

adamchainz avatar adamchainz commented on August 15, 2024

Sorry I can’t really help any more. I hope you can debug the issue my making requests direct to your origin server and tracing them.

from whitenoise.

dorian-adams avatar dorian-adams commented on August 15, 2024

No worries. I almost have it completely working now. I think it was more of a misunderstanding on my part regarding Heroku. To get it working, I had to run collectstatic from my development environment and then push the optimized files to production. Previously, I was running collectstatic from production instead. Works fine now, except for one js file.

Thanks.

from whitenoise.

adamchainz avatar adamchainz commented on August 15, 2024

It does work to run collectstatic locally, and commit the assets, but that’s not the intended method.

The default Django deployment setup has you run collectstatic in your build process, for your production environment. Heroku does this by default, if it can detect your manage.py, unless you disable it with an env var. Refer to the Heroku docs for collectstatic.

from whitenoise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.