Hi all!
I've set up nginx to be the front end web server, mostly forwarding all requests to back end apache, and serving some static content on its own.
There's however one more complex site that uses php scripting to serve all images, and also caching them in the process.
Idea is to (after some php modifying) have nginx check whether the image exist (has already passed php script, and was put in the cache folder) and if it does - serve it immediately, if not - pass it through the php script (reverse proxy to apache).
When the image exists, this works fine, however if the file doesn't exist nginx forwards the request to Apache, but it ignores .htaccess rules that forward the request through php - apache simply returns 404 page...
Apache rewrite rule is:
[code]RewriteRule ^cache/thumbnail/([^<]+)/([^<]+)/?$ thumbnail2.php?file=$2&size=$1&reverse=1 [L] [/code]
I've tried several similar configs, but the idea can be seen through this one.
[code]
server {
listen xx.xx.xx.xx:80;
server_name www.xyz.com;
#location ~ /\. {
# deny all;
#}
location ~ ^/(cache/thumbnail)/ {
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
#rewrite ^/cache/thumbnail/([^<]+)/([^<]+)/?$ thumbnail2.php?file=$2&size=$1&reverse=1 last;
proxy_pass http://xx.xx.xx.xy:80;
}
root /var/www/vhosts/site1/httpdocs/;
}
location / {
proxy_pass http://85.25.78.6:80;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[/code]
Basically, I'm not sure that I've correctly rewrote the rewrite rule (commented line), or that the rest of this config is appropriate for what I'm trying to achieve. Needless to say, it doesn't work when the rewrite rule has been commented out.
Could someone point me in the right direction? Thanks!