2

I have some problem with Nginx (set as reverse proxy) in front of Apache. I'm using Apache to serve PHP files and for applying .htaccess rules.

Nginx works but some of the rewrites in .htaccess does not.

I use timthumb.php to manage media like:

/cache/150/100/file.jpg > /media/thumb.php?src=images/file.jpg&w=150&h=100

Rewrite rules works only in PHP application but it doesn't work with above static file. Nginx returns 404 when I try execute my own static rules.

RewriteEngine On

RewriteRule ^cache/([0-9]+)/([0-9]+)/([a-z0-9_\-\.\/]+)$ /media/thumb.php?src=images/$3&w=$1&h=$2 [L]
RewriteRule ^upload/([0-9]+)/([0-9]+)/([a-z0-9_\-\.\/]+)$ /media/thumb.php?src=upload/$3&w=$1&h=$2 [L]

<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT]
Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
devsbl
  • 23
  • 3

1 Answers1

1

I guess that you are serving your "/upload" and "/cache" directories directly trough nginx - without passing it to apache.

Try following rules:

 location ^~ /upload {
        .......
 }

 location ^~ /cache {
        .......
 }

Before the place where you server your static files in nginx config. Let me know if it works - if not - paste also part of nginx config.

More reading: http://wiki.nginx.org/HttpCoreModule#location

Depends how did you configure your locations during proxy - they have different priorities.

bluszcz
  • 4,054
  • 4
  • 33
  • 52