The problem is slightly more complicated than simply "redirecting stdin/stdout" to a port.
What you need is basically a shell session to your server with a client which runs inside a browser. This answer links to two such shells, AjaxTerm and WebShell
Ajaxterm is a web based terminal. It was totally inspired and works
almost exactly like http://anyterm.org/ except it's much easier to
What worries me a bit is that both programs were last updated in 2008, which in web-years like 50 years ago. Please report back if you manage to run any of them.
A newer and seemingly more supported option is Shell In A Box:
Shell In A Box implements a web server that can export arbitrary
command line tools to a web based terminal emulator. This emulator is
require any additional browser plugins. Most typically, login shells
would be exported this way: shellinaboxd -s /:LOGIN
This command starts a web server at http:// localhost :4200 that allows
users to login with their username and password and to get access to
their login shell.
All client-server communications are encrypted, if SSL/TLS
certificates have been installed.
It is even available in Ubuntu repositories and can be installed with
sudo apt-get install shellinabox