Beyond Code Expose Tunnel 504 Gateway Time-out with WSL2 and Apache
DevOps
Published: June 16, 2024
Author: Andrew Arscott
Expose is a tunnel application, written in PHP that allows you to "expose" your applications to the internet, meaning you can share your website with others whilst developing it, and also test things like webhooks. Built by BeyondCode it provides a free and powerful alternative to ngrok and is the preferred method of tunneling for many PHP and Laravel developers alike.
If you are trying to share your website via the expose Tunnel from BeyondCode but you are getting a 504 Gateway Time-out instead then it is likely that the connection between your computer and the expose server, or your own server if you are self hosting is working fine. The more likely issue is the client on your machine cannot find the website you are trying to tunnel.
If like me you have WSL2 running Ubuntu with an LAMP type stack running with virtual hosts you might find sometimes you attempt to share your website using Expose, but you get a 504 Gateway Time-out error instead. This is likely due to a DNS issue with your machine.
If you have installed Expose on the WSL2 instance, then the default DNS resolver in the config is likely the wrong one. This means that when expose is trying to forward the requests to your local machine, it cannot find the server, so hangs and then eventually times out.
The fix to get this working properly again is a case of giving it the right configuruation for the DNS resolver so Expose can find the development website on your machine.
Open a shell into your WSL2 instance and then type:
cd ~/.expose
This will take you into the expose directory in which the config file (config.php
) is stored. This config file also houses configuration about the expose server you wish to use. It is here where the config might be changed to allow a self hosted instance of Expose to be used.
Open the config file using your favourite editor, in my case, that is nano:
nano config.php
As mentioned above, this Expose config file will contain a a list of the default servers it uses to tunnel, including an endpoint to list all of the available expose servers.
Scroll down until you reach the DNS section:
/*
|--------------------------------------------------------------------------
| 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' => true,
By default, this will likely be set to 127.0.0.1
however, if we set it to true, it instead fallback to use the information provided in the resolve.conf
file on your WSL2 machine.
Now if you restart your machine and then run the expose command to share your website, your issue should be resolved.