Score:0

Can not open localhost in browser with ssh port forwarding

qa flag

I have an issue with access to web page that opens via ssh port forwarding: I do:

ssh [email protected] -L 7182:10.1.11.82:80

172.22.123.71 is a PC which has access to srever's 10.1.11.82 network

Then I open in browser localhost:7182 or 127.0.0.1:7182 and I get 127.0.0.1 refused to connect error.

I check in CLI:

$ telnet localhost 7182

Escape character is '^]'.

HTTP/1.0 400 Bad Request Content-Type: text/html Content-Length: 345 Connection: close Date: Sat, 22 Jul 2023 16:48:49 GMT Server: HTTP Server

"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 400 Bad Request

400 Bad Request

Connection closed by foreign host.Trying 127.0.0.1... Connected to localhost.

It means that ssh forwarding is working. In CLI remote server opens the connection via localhost port 71 82. So the issue is local. I don't use any firewall or iptables or proxy on my Ubuntu 20.04. It is the same for 3 browser FF, Chrome, Brave. I tried to clear cookies. Also when I try the same om similar but different host it works.

I will be very grateful for any clue! As this problem is very annoying.

Erorr in browser

$ sudo netstat -tulpn | grep 7182

tcp        0      0 127.0.0.1:7182          0.0.0.0:*               LISTEN      34957/ssh           
tcp6       0      0 ::1:7182                     :::*               LISTEN      34957/ssh     

Also I've noticed that when I try it in browser the port number disappears in address line. But when I try some localhost port that has no listener the port number does not disappear.

waltinator avatar
it flag
Read `man ssh`, and use one of the `-X` or `-Y` options to pass the Windowing environment.
Aii Aii avatar
qa flag
Thank you for your input, waltinator! But it has nothing common with X11 forwarding. The issue is exactly between browsers and localhost.
Aii Aii avatar
qa flag
In my PC's netstats output I see port listener 127.0.0.1:7182. In telnet output above you can see response from web server on 10.1.11.82. So via CLI the connection works. Probably with Curl the server's output could look better. I just have no idea how can I debug it between browser and localhost.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.