.htaccess issues

Max nginxyz at mail.ru
Fri Feb 10 20:08:45 UTC 2012

10 февраля 2012, 23:40 от Guilherme <guilherme.e at gmail.com>:
> This would fix the problem, but I don't know the directories that has a
> .htaccess file with allow/deny.
> Example:
> Scenario: nginx (cache/proxy) + back-end apache
> root at srv1 [~]# ls -a /home/domain/public_html/restrictedimages/
> ./  ../  .htaccess  image.jpg
> root at srv1 [~]# cat /home/domain/public_html/restrictedimages/.htaccess
> allow from x.x.x.x
> deny from all
> In the first access (source IP: x.x.x.x) to
> http://domain.com/restrictedimages/image.jpg, nginx proxy request to apache
> and cache response. The problem comes in other request from other  IP
> address different from x.x.x.x. Nginx deliver the objects from cache, even
> if the ip address is not authorized, because nginx doesn't understand
> .htaccess.
> I would like to bypass cache in this cases, maybe using proxy_cache_bypass,
> but I don't know how. Any idea?

You could use this:

proxy_cache_key $scheme$remote_addr$host$$server_port$request_uri;

This would make originating IP addresses ($remote_addr) part of
the cache key, so different clients would get the correct responses
from the cache just as if they were accessing the backend directly,
there's no need to bypass the cache at all.


More information about the nginx mailing list