Skip to main content

Using ngrok with Wordpress


This article assumes you familiar with moderate to advanced Wordpress configuration.

To make ngrok work properly with Wordpress installations you usually need to do these two things:

  1. You must instruct ngrok to rewrite the host header and point to the port of your Wordpress install (usually port 80), like so:

    ngrok http 80 --host-header=rewrite --domain
  2. You must ensure that Wordpress understands that it is meant to serve itself from your tunneled hostname. You can configure Wordpress to do that by modifying your wp-config to include the following lines where is replaced with the URL from ngrok:

        define('.COOKIE_DOMAIN.', '');
    define('.SITECOOKIEPATH.', '.');

    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
    $_SERVER['REMOTE_ADDR'] = end($list);
    define( 'WP_HOME', '' );
    define( 'WP_SITEURL', '' );
    $_SERVER['HTTP_HOST'] = '';
    $_SERVER['REMOTE_ADDR'] = '';
    $_SERVER[ 'SERVER_ADDR' ] = '';

This is using the the last hop in the X-Forwarded-For header to set REMOTE_ADDR. If you are using a different header for the original client IP, or multiple forwarding proxies, you will need to adjust this code accordingly.


If you are seeing an error about too many redirects (TOO_MANY_REDIRECTS), you may also need to add the following to your wp-config file as noted in this issue:

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';