server { # Internal image resizing server. server_name localhost; listen 127.0.0.1:9001; access_log off; image_filter_buffer 16M; image_filter_jpeg_quality 85; image_filter_transparency off; image_filter_interlace on; resolver 8.8.8.8 ipv6=off; # Using Google DNS set $width "-"; set $height "-"; if ($arg_w != "") { set $width $arg_w; } if ($arg_h != "") { set $height $arg_h; } location /safe_image { if ($arg_url = "") { return 404; } set_unescape_uri $arg_url; if ($arg_crop = 1) { rewrite /safe_image?(.*) /safe_image/crop?$1 last; } image_filter resize $width $height; proxy_set_header Accept-Encoding "identity"; proxy_set_header Referer ""; proxy_pass $arg_url; location /safe_image/crop { internal; image_filter crop $width $height; proxy_set_header Accept-Encoding "identity"; proxy_set_header Referer ""; proxy_pass $arg_url; } } location /wp-content/uploads { if ($arg_crop = 1) { rewrite /wp-content/uploads/(.*) /wp-content/uploads/crop/$1 last; } image_filter resize $width $height; alias /var/www/example.com/public_html/wp-content/uploads; location /wp-content/uploads/crop { internal; image_filter crop $width $height; alias /var/www/example.com/public_html/wp-content/uploads; } } } proxy_cache_path /var/cache/nginx/wp_image_cache levels=1:2 keys_zone=image_cache:20m inactive=30d max_size=10g; server { listen 80; server_name example.com; root /var/www/example.com/public_html; # ... location /wp-content/uploads { if ($arg_w != "") { return 418; } if ($arg_h != "") { return 418; } error_page 418 = @image_svr; try_files $uri =404; } location /safe_image { if ($arg_url = "") { return 404; } error_page 418 = @image_svr; return 418; } location @image_svr { expires 1M; secure_link $arg_d; secure_link_md5 "$uri$arg_w$arg_h$arg_url your_key"; if ($secure_link = "") { return 403; } if ($secure_link = "0") { return 410; } proxy_pass http://127.0.0.1:9001; proxy_hide_header X-Frame-Options; proxy_cache wp_image_cache; proxy_cache_key "$proxy_host$uri$is_args$args"; proxy_cache_valid 30d; proxy_cache_valid any 10s; proxy_cache_lock on; proxy_cache_use_stale error invalid_header timeout updating; proxy_http_version 1.1; } # ... }