Forums

Can I serve static content from my home directory?

I tried to create a symbolic link from /var/www/static to a folder in my home directory, but nginx wont serve the static content through a symbolic link like it will with files literally in /var/www/static. Am I correct in this understanding?

How can I store my static content (which I want nginx to serve, since it's so fast) in my home directory?

You're correct that nginx won't follow symlinks. It's a security feature. However, you can just copy the files to /var/www/static and they will be directly served from there. If you want to keep everything together for your development, you can then have a symlink from your development area into /var/www/static.

Why html pages in /var/www/static and rended like 'text pages ?

Sounds like nginx isn't sending the correct Content-Type for some reason. Are you using file extension .html or .htm, or something else? I suspect nginx only recognises .html extensions by default - I'm also not sure if case matters. Try making sure your filenames have a lowercase .html extension and see if that fixes things.

If not, I guess this is something for the PAW staff to look into.

It's fine with a lowercase html extension. What extension were you using, Salvatore? Perhaps we should add that.

Hy I have tried both extensions, same problem. Regards

Salvatore

You can test it: http://Salvatore.pythonanywhere.com/test.hml and test.htm

oops

http://salvatore.pythonanywhere.com/test.html andt test.htm

Strange, all is ok now.... Excuse me for the disturb.

Hm, that's odd. Sometimes browser caching behaviour can lead to odd effects like this, but that would be surprising if the filename had changed.

Still, as long as it's working now, let's not jinx it! (^_^)

Thanks :-)

Just to clarify, since someone asked over email.

If you put a file in, eg /var/www/static/foo/bar.jpg, it is served from the url www.my-domain.com/foo/bar.jpg.

Most people want their static files to be served inside a /static/ url. In that case, you have to create an additional subfolder called static inside /var/www/static, so it ends up as /var/www/static/static/.

Clear as mud?

Coming soon, this will become an official feature, so we'll have some kind of sane UI to explain all this stuff...

Is it possible to serve a directory listing of files as static files? I mean so that I don't have to specify individual file names? Say I have multiple static files in a static subdirectory named 'foo'? I was hoping that access to the url '/domain/foo' would show a directory listing but it yields a '404 get' error instead unless I explicitly name the files in the url like '/domain/foo/file1.txt' for example.

In general, it's considered to be a bit of a security hole to have a directory listing of a directory available, so we decided not to publish them.

You could make a very simple view that looks in your directory and generates a listing of the files in it with links to the static urls for the files. That way, only the directory listing is a dynamic page.