Forums

Set expire headers on static files

Hi, I have a web application built on web2py and I am serving static files through nginx. Now I want to add expire header to my static files but couldnt do it yet.

I have tried almost all the available solutions on internet.

I add expire header in web2py response but since static files are not serving through web2py therefore it does not apply expire headers to them.

I have also tried to add expire header through nginx using following command, but no luck:

uwsgi --static-expires-type text/css=3600 uwsgi --static-expires-type application/javascript=3600

I would appreciate any help in this regard

Hi there,

If you're serving static files via our "Static Files" menu on the Web tab, then it's actually uWSGI that's serving them, not nginx. In any case, I'm afraid we don't currently offer the option to adjust the expires header...

What are you trying to achieve, out of interest?

Actually I want static files to have a week long expiry so that they dont load on each page.

The default settings on PythonAnywhere should be solid enough to make sure that stuff is appropriately cached. But if you're building your own web stack with nginx and uwsgi elsewhere (I see that you don't currently have any active PythonAnywhere web apps) then you may need to tweak them.

I have a paid account with the name of my company so for obvious reasons I dont want to use that account in forum, thats why I created a free account and asked the question. Anyway the static content on my site was showing no expire header thats why I wanted to set an expiry. But as you said I cant adjust expire headers so its OK.

By the way, I am overwhelmed with the promptness in responses even for free accounts. Really good work. Keep it up guys.

Ah, OK, I totally understand about the separate account! I just wanted to make sure that you didn't think this was a place for general Python/nginx problems because it would be easy to really confuse matters if we were talking at cross purposes like that :-)