Using S3 as a backup with nginx does not work at the first "few" loads

I have a wordpress site on a multi-server installation (EC2) and I am moving all image uploads to S3. I configured nginx to redirect image requests to S3:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
    add_header Cache-Control public;
    add_header Pragma public;

    error_page 404 = @s3blog;
}

location @s3blog {
    proxy_buffering        on;
    proxy_intercept_errors on;
    proxy_hide_header      x-amz-id-2;
    proxy_hide_header      x-amz-request-id;

    resolver 8.8.8.8;
    proxy_pass $scheme://my-bucket.s3.amazonaws.com;
}

      

This only works after the first page load. I often get complaints from the people in charge of the blog that there are broken images. When I test it well, but the first download doesn't work. The server uses fastcgi for location ~ .php$

.

Is there something I am doing wrong? thanks in advance

+3


source to share


1 answer


Try adding error_page 400 = @ s3blog; above 404.



+1


source







All Articles