Have you ever faced this error? If yes, then you know the pain and time it takes to fix it, and sometimes you just give up because nothing seems to be working. Well, if you are like me, who faced this error while trying to connect your blog to Facebook, Google+ and many other social media sites through Jetpack plugin, then read on.
According to Jetpack support website, https://jetpack.com/support/getting-started-with-jetpack/what-do-these-error-messages-mean/ , this error is faced when you are using Lighttpd web server and it is misconfigured. Maybe that is true, but as for me, I am not using Lighttpd at all (even the package is not installed on the server itself). So “how did I end up with this error message?” was my biggest concern.
As I progressed on the topic, and after reading more than a dozen blogs online, contacting Jetpack support, asking in IRC etc., I was nowhere near the solution but one thing was clear, that Jetpack is trying to connect on port 80 for authorization to my web server (http://) but Varnish HTTP accelerator is using port 80, that’s because error 400 (bad request) is received in the headers.
In order to fix this, there are two methods which are discussed below in detail.
1. You can cheat Jetpack to think that nginx web server is running on port 80 instead of 8080:
This is a one line change that you have to make in the code in “wp-config.php” as below:
$_SERVER['SERVER_PORT'] = 80;
Once done editing the file, save it and try to connect your Jetpack to social media sites using “Publicize” extension and hope it will work.
2. Turn off Varnish and run Nginx on port 80 (for a precise time):
I prefer this more because there is no need to trick Jetpack to think that Nginx is running on port 80 as in the above scenario. This is how it works:
Turn off Varnish HTTP accelerator (“systemctl stop varnish” if you are on CentOS7 or any system that uses systemd) and change your nginx port to 80 (it should be 8080 before depending on your setup) in nginx configuration file. Reload the configuration (systemctl reload nginx). After making this change, you should be able to connect Jetpack to social media sites using “Publicize”. Once you are sure that connection is successful, you can switch back nginx to port 8080 and turn on Varnish HTTP accelerator.
Nginx and Varnish are both very trusted tools to make your websites fly, but when you face such errors, some methods/tricks should be devised in order to fix these kind of situations.
Have any better solution? Please share your valuable feedback with us in the comments section below.