What happens if you install 2 servers on one machine eg: pws and apache - which one is localhost?

Dani AI

Generated

Short answer for : whichever process has bound the network address and port you connect to will answer. The kernel allows only one process to bind a given IP:port pair, so two HTTP servers cannot both own the same address/port at once. and were on the right track — here are practical ways to detect and resolve the conflict, and options to run multiple servers on one machine.

To find which program is listening on a port, inspect the socket table. Useful commands:

ss -ltnp
lsof -i :80
netstat -tulpn

These show the protocol, listening address, PID and program name so you can identify which server is “winning” the port (ss man page).

Ways to run two servers concurrently on the same host:

  • Put one server on a different port.
  • Give the machine multiple IP addresses and bind each server to a different IP (IP aliasing).
  • Use name-based virtual hosts so a single HTTP server serves multiple hostnames (configure as described in the Apache virtual hosts docs: Apache virtual hosts).
  • Front them with a reverse proxy (one front-end on the standard port dispatches to backends on other ports). Containers or lightweight VMs are another isolation option.

A few cautions: only privileged users can bind ports below 1024; firewalls and SELinux/AppArmor can block access; startup order matters because the first service to bind an address takes it. If two services try to claim the same socket, stop one, change its bind address/port, and then restart it.

Recommended Answers

All 2 Replies

Localhost is just an entry in your hosts config file that points it to your local ip (127.0.0.1?), so what ever machine you have set up to look at the port your using (80 http for you?) then it will be that one. If you have multiple servers listening on same port it might be a problem....

Like Atlex said, localhost is just a reference to your IP. You can enter HTTP://localhost, FTP://localhost, localhost:80, Localhost:25, localhost:1337, whatever you'd like and it will go to the intended service through the described port.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.