Where to put the following code?


So I’ve been trying to configure so that gravatars are being loaded from the CDN I currently have. The issue is I don’t know where to put the following code:

location /blog {
sub_filter 'https://secure.gravatar.com/avatar/' 'https://cdn.example.com/avatar/';
sub_filter_once off;


location /avatar { proxy_pass https://secure.gravatar.com$request_uri; }

The instructions are here: https://www.keycdn.com/blog/wordpress-gravatar-cdn/

Any clues?

You can put them at /var/www/example.com/conf/nginx/gravatar.conf

You’ll then have to reload Nginx, but before that, test if the configuration is valid. You can do this using

sudo nginx -t && sudo nginx -s reload


I have added it, nginx conf is fine but it doesn’t seem to work… Deleted all the cache ( cloudflare, wp and pc ) still loading gravatar from their servers.

Your question pertains more to Gravatar specifically, and you shared the source of instructions, you should ask further questions regarding why it might not be working on that blog’s comments as you mentioned that the Nginx configuration is working.


Just to make sure, in the first code, where it says “/blog” I put the folder in which avatars are going to be saved. Ex: /var/www/domain.com/htdocs/avatar

And in the second code in the location part I put just


Is that correct?

Replace /blog with the directory for which you are using Gravatars and replace cdn.example.com with your Zone URL or custom CDN URL.

This is what is mentioned in the instructions given here - https://www.keycdn.com/blog/wordpress-gravatar-cdn/. So it looks correct.

You’re not supposed to put literal ... in the location block like the instructions, it just means any other configuration that you might want.