Tsallake zuwa abun ciki
Localtonet Localtonet Dashboard

Wannan shafin bai samu a cikin Hausa tukuna ba. Ana nuna shi da Turanci.

Reach a virtual host through Localtonet

Taimako kan wannan shafi
A wannan shafin 10 sassa
  1. Why a virtual host needs the right Host header
  2. Before you start
  3. Create the tunnel
  4. Open the HTTP page
  5. Fill in the form
  6. Start the tunnel
  7. Option 1: Set the Host header in the tunnel
  8. Option 2: Add the tunnel's name to the virtual host
  9. Apache
  10. Nginx
  11. Option 3: Use your own domain
  12. Several virtual hosts
  13. Secure it
  14. Common problems
  15. Related pages

Put one site of a local Apache or Nginx server online, including XAMPP, WampServer and MAMP setups with several sites: create an HTTP tunnel and make sure the web server receives a host name it knows.

Why a virtual host needs the right Host header #

With name-based virtual hosts, one web server answers for several sites on the same port. It picks the site by the Host header of each request: a request for mysite.test gets the site whose configuration names mysite.test.

An HTTP tunnel passes the visitor's Host header to your web server unchanged. A visitor who opens the tunnel's address therefore sends the tunnel's host name, for example a name that ends in .localto.net, and not mysite.test. Your web server doesn't know that name and answers with its default site, which is usually the first one in the configuration, or the XAMPP or WampServer start page.

There are three ways to fix this. Pick one:

OptionWhat you changeBest for
Set the Host header in the tunnelA request header in the tunnel's settings. Nothing on the web server.A quick look at a static or simple site.
Add the tunnel's name to the virtual hostOne line in the web server's configuration.Applications that build links and redirects from the host name.
Use your own domainThe tunnel uses a domain you own, and the virtual host is named after it.A site that should keep one address.

Before you start #

  • A Localtonet account and the Localtonet client connected with your AuthToken on the computer that runs the web server. See Quick start.
  • A virtual host that works in a browser on that computer, for example http://mysite.test.
  • The port the web server listens on. XAMPP and WampServer use 80. MAMP uses 8888 unless you changed it.

Create the tunnel #

  1. Open the HTTP page #

    Open My Tunnels › HTTP and expand Create HTTP Tunnel.

  2. Fill in the form #

    FieldWhat to enter
    URL typeRandom subdomain for options 1 and 2. For option 3, choose Custom domain.
    Device tokenThe token the Localtonet client on the computer uses.
    Server regionChoose a region close to your device for lower latency.
    Local IP address127.0.0.1. Enter the address, not the name of the virtual host: the name travels in the Host header.
    Local portThe web server's port, for example 80.

    Select Create tunnel.

  3. Start the tunnel #

    The tunnel appears under Your tunnels. Select Start and note the public address in the URL column. If you open it now, you see the web server's default site. The next step fixes that.

The tunnel form is described in full on the HTTP / HTTPS page.

Option 1: Set the Host header in the tunnel #

The tunnel can replace the Host header before a request reaches your web server. The setting is a request header named Host:

  1. Select Settings on the tunnel's row.
  2. Next to Headers, select Manage. The HTTP headers window opens on Request headers.
  3. Select Host under Suggestions, or select Add a request header and type Host as the name.
  4. As the value, enter the name of your virtual host, for example mysite.test. The suggestion fills in localhost; replace it. Enter only the host name, without http:// and without a path.
  5. Select Save.

The dashboard describes the Host request header like this: your service receives this host name instead of the tunnel address, which is useful when a local web server picks the site by host name. Without a Host request header, your service receives the host name the visitor used.

Open the tunnel's address again. The web server now receives Host: mysite.test and answers with that site. To go back, remove the header and save.

The application also sees the local name. Software that builds links and redirects from the Host header, or from a configured site address, now sends visitors to mysite.test, which only exists on your computer. If pages load without styles or a login redirects to the local name, use option 2 or 3 instead.

The API has the same setting as the Host header override of an HTTP tunnel. See API. Other request and response headers are covered on Headers and rewrites.

Option 2: Add the tunnel's name to the virtual host #

Tell the web server that the tunnel's host name belongs to your site. Copy the host name from the tunnel's URL, without https://, and add it as an alias. Leave the tunnel's Headers empty.

Apache #

In XAMPP the virtual hosts are in apache\conf\extra\httpd-vhosts.conf. Add a ServerAlias line:

httpd-vhosts.conf
<VirtualHost *:80>
    ServerName mysite.test
    ServerAlias <TUNNEL_HOST>
    DocumentRoot "C:/xampp/htdocs/mysite"
</VirtualHost>

Restart Apache.

Nginx #

Add the tunnel's host name to server_name:

mysite.conf
server {
    listen 80;
    server_name mysite.test <TUNNEL_HOST>;
    root /var/www/mysite;
    index index.html index.php;
}

Check the configuration and reload Nginx:

Terminal
sudo nginx -t && sudo nginx -s reload

An HTTP tunnel keeps its subdomain until you delete the tunnel, so the alias stays valid across restarts.

Option 3: Use your own domain #

When the tunnel runs on a domain you own, visitors send that domain in the Host header, and you name the virtual host after it. No header override and no alias are needed, and links that the application builds are correct.

  1. Add the domain to your account and create the HTTP tunnel with URL type set to Custom domain. The steps are on Custom domains. Custom domains need Balance.
  2. Set ServerName (Apache) or server_name (Nginx) of the virtual host to that domain, as in the snippets above.

Custom subdomain works the same way with a name of your choice instead of a random one. It also needs Balance.

Several virtual hosts #

One HTTP tunnel has one public address and reaches one site. For each additional virtual host, create another HTTP tunnel to the same Local IP address and Local port and apply one of the options to it. The Free plan allows one tunnel in total. See Plans and Balance.

Secure it #

A development site is often not ready for strangers. An HTTP tunnel can ask visitors to identify themselves before a request reaches your web server:

  • Basic Authentication? in the tunnel's Settings asks visitors for a user name and password.
  • IP Restriction › Manage lets only the addresses you list connect. It needs Balance.
  • SSO Providers makes visitors sign in with an identity provider first. It needs Balance.

All three are described on Access control. For a demo, Expiration Date stops the tunnel on a date you set. See Limits and expiration.

Common problems #

I see the XAMPP or WampServer start page, or the wrong site

The web server didn't recognise the host name and served its default site. Apply one of the three options. With option 1, check that the header's name is Host and its value matches ServerName or server_name of the site. With option 2, check the alias for typing mistakes and restart the web server.

The page loads without styles, or links go to mysite.test

The application builds its addresses from the local name. Use option 2 or 3 so the application sees the public name. Applications with a stored site address need that address changed as well: for WordPress, update the site URL to the tunnel's address or use a custom domain.

The site redirects to http:// and the browser shows a warning or a loop

Visitors use HTTPS on the tunnel's address, while the tunnel talks plain HTTP to your web server. An application that forces HTTPS by itself may not notice that the visitor is already on HTTPS. In Headers, the request header X-Forwarded-Proto from the Suggestions, with the value https, tells such an application that visitors use HTTPS.

Visitors see a Localtonet warning page first

On accounts without Balance, Localtonet shows this page once to each visitor of an HTTP tunnel. Requests that carry a localtonet-skip-warning header with any value skip it, and so do tunnels on accounts with Balance.

My web server only listens on HTTPS

Set the tunnel's Local port to the HTTPS port, usually 443, and turn on Is SslStream? in the tunnel's Settings. That switch is for local services that use HTTPS or TLS themselves.

"You need to purchase balance to use this feature."

Custom subdomain, Custom domain, IP Restriction and SSO Providers need Balance. Add it under Balance.

Taimako