All Articles
Tutorialslaravelphpwsl2exposetunnelinglocal-development

Fixing Expose 504 Gateway Timeout on WSL2

18 November 2024· 4 min read· Andrew Arscott

Expose is a tunnel application written in PHP that allows you to share your local applications with the outside world — useful for demoing work in progress and testing webhooks. Built by BeyondCode, it provides a free and powerful alternative to ngrok and is the preferred tunnelling method for many PHP and Laravel developers.

The Problem

If you are trying to share your website via an Expose tunnel but getting a 504 Gateway Timeout instead, the connection between your machine and the Expose server is likely fine. The more probable cause is that the Expose client on your machine cannot find the website you are trying to tunnel to.

If you are running WSL2 with Ubuntu and a LAMP-style stack with virtual hosts, this is a common stumbling block. The culprit is almost always DNS.

When Expose is installed inside a WSL2 instance, the default DNS resolver in its config is likely pointing to the wrong address. This means that when Expose tries to forward incoming requests to your local server, it cannot resolve the hostname, hangs, and eventually times out.

The Fix

The fix is to point Expose at the correct DNS resolver so it can find your local development site.

Open a shell into your WSL2 instance and navigate to the Expose config directory:

cd ~/.expose

This directory contains config.php, which stores all Expose configuration — including which server to tunnel through and, importantly, the DNS resolver.

Open the config file in your editor of choice:

nano config.php

Scroll down until you find the DNS section, which will look something like this:

/*
|--------------------------------------------------------------------------
| DNS
|--------------------------------------------------------------------------
|
| The DNS server to use when resolving the shared URLs.
| When Expose is running from within Docker containers, you should set this to
| `true` to fall-back to the system default DNS servers.
|
*/
'dns' => '127.0.0.1',

Change the value from '127.0.0.1' to true:

'dns' => true,

Setting this to true tells Expose to fall back to the system DNS servers defined in your WSL2 instance's /etc/resolv.conf file, rather than trying to use a hardcoded resolver that doesn't work in this context.

Save the file, restart your machine, and then run your Expose share command again. The 504 errors should be gone.

Have thoughts on this? Get in touch.