How to serve all existing static files directly with NGINX, but proxy the rest to a backend server.

Use try_files and named location block (‘@apachesite’). This will remove unnecessary regex match and if block. More efficient. location / { root /path/to/root/of/static/files; try_files $uri $uri/ @apachesite; expires max; access_log off; } location @apachesite { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8080; } Update: The assumption of this config is that … Read more

Django – Static file not found

I confused STATIC_ROOT and STATICFILES_DIRS Actually I was not really understanding the utility of STATIC_ROOT. I thought that it was the directory on which I have to put my common files. This directory is used for the production, this is the directory on which static files will be put (collected) by collectstatic. STATICFILES_DIRS is the … Read more

What’s the point of Django’s collectstatic?

Collect static files from multiple apps into a single path Well, a single Django project may use several apps, so while there you only have one myapp, it may actually be myapp1, myapp2, etc By copying them from inside the individual apps into a single folder, you can point your frontend web server (e.g. nginx) … Read more

How to serve static files in Flask

In production, configure the HTTP server (Nginx, Apache, etc.) in front of your application to serve requests to /static from the static folder. A dedicated web server is very good at serving static files efficiently, although you probably won’t notice a difference compared to Flask at low volumes. Flask automatically creates a /static/<path:filename> route that … Read more