Proxying WP_HTTP Requests
If you just want to set up your Human Made proxy, this is not the page you need. For that, see Set up your web proxy.
This guide tells you how to proxy WordPress HTTP API requests from a WordPress site through the HM proxy. You’ll only need to do this if there are IP address based access restrictions on the host name that your site needs to connect to. (For example, some clients have APIs which are only accessible through the HM proxy).
You may also choose to proxy all WordPress HTTP API requests through the HM proxy using the method below for added security.
There are couple of easy ways to do this, one using the Charles HTTP proxy app ( Which is available for Mac, Windows, and Linux, but this guide assumes you’re using Mac ), and another using SSH Tunnels which does not require any specific tooling, just a terminal.
A. Using Charles HTTP Proxy A. Using Charles HTTP Proxy
- Start Charles.
- Connect to the HM proxy as normal.
- Add the following constants to your site’s
define( 'WP_PROXY_HOST', 'x.x.x.x' ); define( 'WP_PROXY_PORT', 8888 );
x.x.x.xis your local machine’s network IP address. You can find this in the Help -> Local IP Address menu in Charles.
In OS X, go to System Preferences -> Network -> Advanced -> Proxies and ensure that both the Secure Web Proxy and the Web Proxy are set to
- Click SOCKS Proxy on the left and note down the port number.
- In Charles, go to Proxy -> External Proxy Settings, enable the SOCKS proxy, and set it to
xxxxis the port you just noted down from your network settings.
If you need to enable proxying for HTTPS URLs:
- In Charles, click Help -> SSL Proxying -> Install Charles Root Certificate and follow any instructions.
- Trigger an HTTPS request to the the domain name you want to enable SSL proxying for.
- In Charles, right-click the host name when it shows up in the list on the left hand side, and click Enable SSL Proxying. Future HTTPS connections to that host will now be proxied through Charles.
B. Using SSH Tunnels: B. Using SSH Tunnels:
- Open a new terminal
- Initiate a new SSH Tunnel using
ssh -fND localhost:8888 USER@eu-west-1.aws.hmn.md
- Add the following constants to WordPress
define( 'WP_PROXY_HOST', 'socks://10.0.2.2' ); define( 'WP_PROXY_PORT', 8888 );
USERwith your HM Proxy username.
- Feel free to change the port from
8888to anything available on your host machine.
-fis for running the process in the background, feel free to omit to know if the connection drops for some reason.
10.0.2.2is the magic IP for Vagrant hosts, change it to your host IP if you’re not running WordPress in Vagrant.
Check that it works Check that it works
You can test everything is working by adding this code to your site:
$request = wp_remote_get( 'http://ipchicken.com' ); var_dump( $request ); exit;
At this point, Charles (if you’re using it) may prompt you to allow the connection. Click Allow.
Find Name Address in the output and it should be set to something that ends in
amazonaws.com. If it is, the HTTP API is being correctly proxied.