As local network localhost address

Asked

Viewed 10,669 times

0

I am testing a web application locally by pc and mobile, connect on pc using http://localhost and by cell phone http://192.168.xx.xx:8080. And I wonder if you have how to change the host address to a fixed address (for example http://test.com), so I can access from any device without having to grab the server ip(I’m using Xampp).

Thanks in advance.

  • I would set my machine IP as fixed :)

  • so I wanted to access it through a test.com address, not the machine’s IP address.

  • To my knowledge, you can do this by writing an address in the archives hosts windows and pointing to the IP 127.0.0.1. Now, so that the phone also recognizes the same address, I do not know if it has.

  • 1

    There’s no way, @Wallacemaxters. It’s a DNS done just inside Windows. If he wants to do this, he will have to buy the domain and host the DNS for his machine. So he would have a public address.

  • Yes there is a way. If in the hosts files enter the ip followed by the address, any device ON THE SAME NETWORK can access usand http://endereco/

2 answers

5


Local Network Access (LAN)

If you are on the same network you can use the server name. To know your computer name on Windows Open the Command Prompt and type hostname:

Descobrindo o hostname

In my case it is DEV004W, then just access using this hostname over the net:

http://dev004w/

One observation is that your application cannot reference Resources as localhost, example:

<link rel="stylesheet" href="http://localhost/estilo.css">

This will cause an error as you are searching for the file estilo.css on the machine you are accessing, then refer to IP or hostname server.

Internet access (WAN)

Should you not on the same network server (machine running XAMPP/Wampp/IIS/Apache) you can use NO-IP. It is a service that provides a Free DNS for dynamic Ips.

  • but for example if I log into my phone at http://dev004w/ it can access the server?

  • 1

    If I understood what Kadu meant, "yes", if it’s on the same network

  • @Rafael as Wallace said and as my answer begins Se estiver na mesma rede você pode usar o nome do servidor.. That is, if your phone is on the wifi of your host.

  • @Rafael updated the answer by adding an option for when not on the same network.

-2

There are several ways to do this, and the previous answer is not the best one, but it might break a branch.

There are two practical options:

  1. If you just want to leave something more visually beautiful for yourself, and more practical, creating a virtual host can be a good one. A Vhost is nothing more than a virtual server. You can give the name you want to it: http://dev.test/ (if you want to). But there are different ways to do this, in different types of installations. Just "googlar" anything like "how to create a virtual host" you find easy. But attention! Virtual Host only serves in your local environment. No use trying to access from outside your network.

  2. If you need something visual to show your customers, like, "go there to see how it’s going"... You must create a server and acquire a domain http://dev.test/. This will cost (obvious) and may give you more work. It is possible to open your PC to the world by making it a web server, but it is also dangerous as it can invade your PC and destroy your jobs and your dreams. I advise to rent a web hosting service.

  • I recommend changing the term Nutella to another that does not feature offense.

  • I have not come to offend anyone, on the contrary, I have come to help. If someone can be offended by this, it is a person’s problem, not mine.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.