Fix
Service works on localhost but not from another machine
The service listens on 127.0.0.1 only, so connections to the machine's real address are refused. Make it listen on 0.0.0.0 or on that address.
Likely causes
- The program binds to
127.0.0.1(often a default, or a--host/bindsetting). - A firewall on the server or on the path, which shows as a timeout instead of a refusal.
Diagnose
Run these in order. The output is what each printed on a lab's real Linux machines.
-
backroom:~# nc -w 1 127.0.0.1 7000 - On the server itself the service answers.
rye 12 sourdough 4 croissants 30
-
till:~# curl -sv http://10.0.1.12:7000 - From another machine,
Connection refused: nothing listens on 10.0.1.12:7000.* Trying 10.0.1.12:7000... * connect to 10.0.1.12 port 7000 from 10.0.1.10 port 38640 failed: Connection refused * Failed to connect to 10.0.1.12 port 7000 after 0 ms: Could not connect to server * closing connection #0
-
backroom:~# ss -tlnp -
ss -tlnpshows why: port 7000 listens on127.0.0.1:7000, while 80 and 8080 listen on0.0.0.0, every address.State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess LISTEN 0 5 127.0.0.1:7000 0.0.0.0:* users:(("stockdb",pid=162,fd=5)) LISTEN 0 5 0.0.0.0:8080 0.0.0.0:* users:(("python3",pid=152,fd=3)) LISTEN 0 4096 127.0.0.11:34969 0.0.0.0:* LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=139,fd=6))
Fix
-
sed -i 's/listen 127.0.0.1:80;/listen 80;/' /etc/nginx/http.d/orders.conf restart-orders - Change the listen address, then restart the service (
restart-ordersis this lab's restart of nginx). For your own program, the same.
Break it and fix it yourself
Each lab is a small network of real Linux machines in your browser, where this fault happens.
- Ports and sockets: one address, many programs : its challenge "The order page fails on the till" set the fault for you to find and fix.