Main Content

Fixed: JetPack and Varnish 502/503 Error on Nginx

tl;tr: Disable Varnish, connect JetPack, re-enable Varnish.

Varnish & JetPackI’m not a server guy, but I do run my own server and it’s not bad most of the time. But lately I’ve been having errors with JetPack where it fails to connect with WordPress.com properly. On activation, it hits WordPress.com just fine but on its way back, it hits a 502 or 503 error on my Nginx server. I’ll reload the page and it’ll say it works, but I won’t get all the benefits of WordPress.com like being able to write posts or update plugins via WordPress.com.

To fix this, I searched Google for more than an hour trying different things and ended up just disabling Varnish and connecting JetPack. To me, this is more of a work around than a solution, but it’s fixed and I’m happy.

Here’s the details if what I did. Hopefully it works for you.

First go into your site’s available directory:
cd /etc/nginx/sites-available

Edited the site configuration file:
vi default

Commented out the current listen line.
From listen 127.0.0.1:8080; to #listen 127.0.0.1:8080;

And added listen 80; in all the places the previous line showed up.

Save the file: [esc]:wq

Stop Varnish: service varnish stop

Restart Nginx: service nginx restart

Then go into WordPress and connect JetPack as you normally would. It should work fine this time.

To get Varnish working again, go back into the configuration file and comment out the listen 80; lines and un-comment the #listen 127.0.0.1:8080; lines.

Restart Nginx: service nginx restart

Start Varnish: service varnish start

Again, this is more of a work around, but it’s better than nothing.

I actually decided to go without Varnish for a while to see how things performed. Right now it’s causing more of a pain than it’s worth.

Hat tip to Useful Mix for coming up with the solution. There are also a few good tips in the comments over there that may work for you too.


Leave a Reply