Here are some "cheat codes" or helpful commands and tips for working with Serveo, SSH, and local web servers. These commands will help you streamline your development process and take advantage of the tools you're working with.
1. Basic Serveo Command:
This command establishes a reverse SSH tunnel to expose your local server to the internet.
- Explanation:
-R 80:localhost:80: This tells Serveo to listen on port 80 of their remote server and forward requests tolocalhost:80(your local machine's web server).serveo.net: Connects to Serveo’s server to establish the tunnel.
2. Custom Subdomain on Serveo:
If you want a custom subdomain for your Serveo URL, you can specify one like this:
- Example: This will give you a public URL like
https://mycustomsubdomain.serveo.net.
3. Expose Specific Ports Other Than 80 (HTTP):
If your server is running on a different port (e.g., 3000 for Node.js or Spring Boot), you can specify that port in the Serveo command:
- Explanation: This forwards requests on port 80 of the Serveo server to port 3000 on your local machine.
4. Keep Your SSH Tunnel Alive:
By default, SSH sessions can time out if idle for too long. To prevent this from happening, you can add these options to keep the session alive:
- Explanation:
ServerAliveInterval=60: Sends a "keep-alive" signal every 60 seconds.ServerAliveCountMax=5: Allows up to 5 missed "keep-alive" signals before disconnecting.
5. Reverse SSH Tunnel for Multiple Local Services:
If you want to expose multiple services (e.g., a web server on port 80 and a database on port 3306), you can use the following:
- Explanation: This command exposes both your local HTTP server on port 80 and a MySQL database on port 3306 via the Serveo tunnel.
6. Expose a Local Application Behind a Proxy (e.g., Docker or VMs):
If you have your application running in Docker or a virtual machine (VM), you can expose it through Serveo by mapping the right port to the local service:
- Explanation: If your app is running in Docker on port
8080, you can expose it via Serveo's remote80port.
7. Automatic Restart of Serveo Tunnel (using tmux or screen):
If you want to make sure your SSH tunnel continues to run even after closing the terminal, you can use tools like tmux or screen:
- Explanation:
tmuxwill keep your session running even after you close the terminal. You can always reconnect to the session later.
8. Troubleshooting Serveo Tunnel Issues:
If your tunnel is not working as expected, check these things:
- Verify Port Binding: Ensure the local port (e.g.,
localhost:80) is not blocked by a firewall or another application. - Check Server Response: Use
curlto check the response from your local server: - Verify Public URL Access: If your local server works fine but the Serveo URL does not, verify the tunnel is still open and running in your terminal. Re-run the
sshcommand if necessary.
9. Access Web UI of SSH Sessions (Web Console for SSH):
Some SSH providers like Serveo might allow you to view your session output in a web UI. If you're looking to view logs or status, it's useful to have a tail command running to monitor logs in real-time:
- Explanation: This shows the real-time access logs of your Apache web server, so you can see what requests are coming in.
10. Expose a Specific Local Page Instead of Entire Server:
If you only want to expose a specific local page (like a dashboard) rather than the entire server, you can use a proxy server locally to route that specific page. For example, using nginx:
Then use the same Serveo command to expose it.
Keep the Tunnel Running
ReplyDeleteAs long as the SSH session is open, your local server will remain accessible via the public Serveo URL. If the session closes (e.g., you close the terminal), the tunnel will stop, and the URL will no longer be available.
If you want to keep it running in the background, you can use the -f flag with the SSH command:
ssh -f -N -R mysubdomain.serveo.net:80:localhost:5500 serveo.net
This command runs Serveo in the background (-f) and doesn’t execute any remote commands (-N).