Home >Technology peripherals >It Industry >Accessing localhost from Anywhere
Access Your Localhost From Anywhere: A Developer's Guide to Secure Tunneling
You've painstakingly crafted a website design on your local machine, complete with sample content. Now, you need to test it on various mobile devices and share it with clients – without the hassle of deploying it to a public server prematurely. This guide explores several tools that create a secure tunnel from the internet to your localhost, allowing remote access and streamlined testing.
This article covers: ngrok, PageKite, localtunnel, boringproxy, and BrowserStack.
Key Advantages:
How it Works:
Secure tunnel services establish a connection between the internet and your local machine. A public URL is provided; incoming requests to this URL are forwarded to your localhost server. The complex setup is handled automatically; you simply install the application and point it to your localhost.
Important Note on Virtual Hosts:
If you use virtual hosts, ensure the public URL provided by the tunneling service is added as a ServerAlias
in your httpd.conf
file (or equivalent configuration file for your web server). For example:
<code><virtualhost> DocumentRoot "/Users/patcat/Web" ServerName mytestsite.test ServerAlias 350c0f8e.ngrok.com </virtualhost></code>
ngrok:
ngrok (available for Windows, macOS, and Linux) creates a tunnel and allows traffic inspection and replay for testing. Basic features are free; advanced features (custom subdomains, reserved domains) require a paid plan. ngrok's key advantage is its lack of dependencies.
Using ngrok:
./ngrok http 80
http://42e474ef9799.ngrok.com
).ngrok's traffic inspector (accessible at http://localhost:4040/
) allows you to analyze past requests.
ngrok Advanced Features:
ngrok http -auth="username:password" 80
ngrok http -subdomain nogophersinmytunnel 80
ngrok http -hostname="tunnel.yourdomain.com" 80
ngrok http 192.168.0.27:80
ngrok tcp 22
PageKite:
PageKite (Python-based, supports Windows, macOS, Linux, and Android) is a robust, long-standing alternative to ngrok. It offers a free trial, followed by a pay-what-you-want model. It includes a built-in firewall blocking common attack vectors.
Using PageKite:
pagekite.py 80 hurrygetintothefancytunnel.pagekite.me
(replace with your chosen subdomain).PageKite Advanced Features:
pagekite.py /path/to/folder igotthattunnelvision.pagekite.me
pagekite.py 80 terelekkayatuneli.pagekite.me password/username=password
pagekite.py 80 arcadefirecamethroughmywindow.pagekite.me ip/1.2.3.4=ok ip/4.5.6=ok
localtunnel:
localtunnel (Node.js, Go, and C#/.NET clients) is a straightforward tunneling service.
Using localtunnel:
npm install -g localtunnel
lt --port 80
localtunnel Advanced Features:
lt --port 80 --subdomain platypusestunneltoo
boringproxy:
boringproxy is a free, open-source (MIT license) option, primarily focused on self-hosting. It's available as a single executable for Linux and Windows (macOS support is untested).
BrowserStack:
BrowserStack offers virtual machines and browser testing capabilities. While it doesn't directly expose your localhost, its browser extension facilitates access via their servers (paid service).
Conclusion:
Numerous tools simplify accessing your localhost remotely. ngrok and PageKite stand out for their ease of use and comprehensive features. Choose the tool that best suits your needs and security requirements. Remember to prioritize security when exposing your localhost to the internet.
FAQs: (Answers incorporated directly into the main text for better flow)
The above is the detailed content of Accessing localhost from Anywhere. For more information, please follow other related articles on the PHP Chinese website!