15.14. Troubleshooting proxy issues

The plugin uses a well-known PHP HTTP client, named as Guzzle. This library is used widely, and, at the time of writing, it has about 20k stars on its GitHub repository. It is a well-tested library. The plugin makes proxy requests by using this library. Also, the plugin is tested intensively with a proxy before every new version. So, the plugin’s proxy feature works. If your proxy does not work, because the underlying HTTP client library and the plugin itself are well-tested, there is probably something wrong with the proxy you are using or how you define it. In this page, we will see how to debug a proxy.

Important

To use the following commands, you should connect to your server over ssh. Also, your server must have curl command installed in it. If you are not able to connect to your server over ssh and you have PHP knowledge, you can use PHP’s curl functions. Other programming languages that you are comfortable with can also be used. However, we will use curl command in this tutorial, because it is one of the easiest ways to do this.

You can test if your proxies work with your server via the command line, using the following command:

$ curl -I -x <proxy-url> <target-url>
<proxy-url>
Replace this with your proxy’s URL. For example, http://1.2.3.4:3001 or https://5.6.7.8:76.
<target-url>
Replace this with the URL of the website you want to connect through a proxy. We will use my own website, http://turgutsaricam.com.

You should replace <proxy-url> and <target-url> with correct values. For example, I run a proxy on my computer at http://localhost:6666. When I run the curl command to connect to http://turgutsaricam.com via http://localhost:6666, I get this:

$ curl -I -x http://localhost:6666 http://turgutsaricam.com
HTTP/1.0 200 OK
Via: 1.1 tinyproxy (tinyproxy/1.8.4)
Content-Type: text/html; charset=UTF-8
Link: <http://turgutsaricam.com/wp-json/>; rel="https://api.w.org/"
Server: Apache
Date: Sat, 15 Aug 2020 07:05:58 GMT

As you can see, the request succeeds with HTTP 200 status code, and its Via header contains the name of the proxy server I am using, which is tinyproxy. If the proxy URL was wrong, I would get an output like below:

$ curl -I -x http://localhost:6667 http://turgutsaricam.com
curl: (7) Failed to connect to localhost port 6667: Connection refused

If I use a paid proxy with a wrong protocol (https) to connect to my website, the command keeps running for a long time and then outputs this:

$ curl -I -x https://x.y.z.t:30001 http://turgutsaricam.com
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number

The error I get is curl: (35) error:1408F10B:SSL. When I search for the error on Google, I find this StackOverflow question. The answer of the question says that the proxy should be used via http, not https. When I do that, I get this:

$ curl -I -x http://x.y.z.t:30001 http://turgutsaricam.com
HTTP/1.0 407 Proxy Authentication Required
Proxy-Authenticate: Basic realm="proxy"
Proxy-Connection: close
Content-type: text/html; charset=utf-8

As you can see, the proxy can now be connected, and the response indicates that the proxy needs authentication (Proxy Authentication Required). If you get an output that says Authentication Required, then there might be something wrong with your proxy’s configuration. Probably, you should configure your proxy to allow your server’s IP address. If you should provide your proxy user and password in the proxy URL, then changing the proxy URL from http://x.y.z.t:30001 to http://<username>:<password>@x.y.z.t:30001 might do the job. For more information on how to provide proxy URLs to the plugin, you can see Proxies setting.

Important

Your proxy might be working correctly, but the target site might have blocked your proxy. You should analyze the output of the curl command to understand what is wrong.

To sum up, you can debug your proxies by using curl command. If you can connect to your proxy successfully via this command, it means that the plugin will be able to do so as well. You just need to make a request to the target site with curl command and check out the output. The output will provide you with useful information to fix the problem. If you do not understand something existing in the output, you can just Google it. Probably, someone already ran into the same issue, and someone else provided a solution for it. If you cannot find a solution yourself, you can check out the documentation of your proxy or get in touch with your proxy provider or your server’s support team.