I'm using nginx as a reverse proxy for a Drupal 7 site running on Apache2.

When I try to view a thumbnail I get the Drupal 404 page saying that the location is not found.

I have implemented the location rules to rewrite requests to the thumbnail to index.php and the error message includes this rewritten request.

These are my nginx location blocks:

location @rewrite {
    rewrite ^/(.*)$ /index.php?q=$1 last;

location ~ ^/sites/.*/files/styles/ {
    try_files $uri @rewrite;

# Try to serve files with Nginx if possible
location / {
     try_files $uri @proxy;

# Pass on php to Apache
location ~* \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include /etc/nginx/proxy_params;

location @proxy {
    proxy_pass    ;
    include /etc/nginx/proxy_params;

The url of a thumbnail looks like this:


The error message displayed is:

The requested page "/index.php?q=sites/default/files/styles/thumbnail/public/pictures/picture-1-1437996028.jpg&itok=19uLP_Ax" could not be found.

I have tried setting the flag to allow insecure content generation (without a token) to test with. Obviously I've removed that flag.

1 Answer 1


that is similar to me, i added this line in my nginx vhost config,

location ~* /sites/default/files/styles/ {
    if (!-e $request_filename) {
    rewrite  ^/(.*)$  /index.php?q=$1  last;

you need to reload to make the image display, hope someone can improve my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.