Answer the question
In order to leave comments, you need to log in
Can you explain on your fingers about the essence of localhost and ports?
Hello!
Please explain in simple terms.
What is localhost in the address bar?
Why are there different ports?
Where is this localhost, in what directories?
Thanks
Answer the question
In order to leave comments, you need to log in
If a person who is not familiar with arithmetic wants to understand what "two plus three equals five" means, it is not enough for him to explain what "two" is, or what "plus" is! Same here. To understand what localhost is, you first need to understand what a host is in general, what a network is, what a hostname is, what a server is, how it all relates to addresses and port numbers, and those - with, in fact, one specific computer ( which, depending on the context, can be called both "host", and "server", and "localhost"). So, just in case:
A computer connected to a network is called a host . It is addressed by a unique address or name . One name (i.e. one host) can correspond to several different addresses.
When a host is addressed by name, that name is first resolved to the address of the host that is actually being addressed. On the network, this is usually done by DNS (which, by the way, is also a server ... but that's another story, which is not so important for understanding the essence now), but if there is no DNS, the name-address correspondence can be registered in the hosts file on the host. If a certain hostname is not registered there, it will not be possible to refer to it by name ... although direct access to the address will work.
Serveris a program that responds to requests from the network. The computer on which it runs is also called a "server". Moreover, even if the execution of the program is suspended (for example, they are performing maintenance or the server program has crashed), this computer will still be called the "server", because it is intended mainly to execute this program.
On one computer (=host, server) several different server programs can be simultaneously executed. In order to refer to a specific one (the address is the same for everyone!), the TCP / IP protocol uses different port numbers .
If the computer is running, for example, an HTTP server (= Webserver, for example, Nginx or Apache), it "listens" on port 80, and if it is not running, no one is listening on port 80, and if you turn to such a host (= server, computer) to its address on port 80, no answer will come ... although the host itself will be available.
For various well-known types of server programs (in this case they also talk about "services" or "protocols", which in this context is almost the same), it is customary to use well-known port numbers, and for the most common ones (like the same HTTP), you can even not specify the port number when accessing, as we usually do in the browser line, because the client automatically uses the default port number, in this case 80. But, in principle, any service can be (reconfigured) used on any port ... if, of course, it makes sense. The only thing that is impossible is to use different servers on the same port at the same time.
And, finally, it would be completely stupid if, in order to access some server on one host on the network, another computer would also be needed from which to access. So we came up with the opportunity to access the server program from the same host on which it is running, i.e. locally , and in order not to guess at what address or name to do this, they introduced the concept of localhost.
localhost is the "well-known" host name for itself and corresponds to the IP address 127.0.0.1. This is a common convention that you just need to know. If they say "install the server on localhost", it means "install on the same computer from which to access this server".
What is localhost
Why are there different ports \
Quite lazy, right?
What is localhost in the address bar?
Why are there different ports?
Where is this localhost, in what directories?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question