Welcome! Log In Create A New Profile

Advanced

how to halt loading anything but images?

Posted by honeylemon 
how to halt loading anything but images?
February 20, 2010 02:42PM
Hello,

I currently have nginx running alongside apache, with nginx loading only images at the moment (gif, jpg, png) via a subdomain (images.foobar.net). I want to config nginx so that it [b]only[/b] loads images, anything else (php, html, etc) would simply be refused. Is this possible? And if so, how?

Thank you
Re: how to halt loading anything but images?
February 20, 2010 03:27PM
Something like:

[code]
# serve images
location ~* \.(jpe?g|gif|png)$ {
expires max; # or not if you prefer
}
# don't serve other types
location ~* \.(php|html?|js|css|xml)$ { # add other types as needed
return 404; # or whatever other error/redirect you prefer
}
[/code]

--
Jim Ohlstein
Re: how to halt loading anything but images?
February 21, 2010 02:12AM
Thank you very much Jim.

May I ask what "expires max" does? I can't find info on it anywhere on nginx.com.
Re: how to halt loading anything but images?
February 21, 2010 03:13AM
It sets headers for the image:

From http://wiki.nginx.org/NginxHttpHeadersModule:

[quote]max assigns the time of 31 December 2037 23:59:59 GMT to the Expires header and 10 years for the Cache-Control header[/quote]

This assumes these files will not change, of course. Practically these files will eventually be deleted from a browser's cache as it get filled or flushed.

You can always use:

[code]
expires 30d;
[/code]

if you think these images may occasionally change and retain the same name.

--
Jim Ohlstein
Re: how to halt loading anything but images?
February 21, 2010 03:18AM
Great info, thank you again Jim!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 191
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready