In this article, we will show how to access localhost of a remote server. Localhost corresponds to the hostname of the device that currently runs your application. It is the DNS name for the local loop back address, which is
127.0.0.1 . So, instead of
127.0.0.1 , you type
If you are running your Python application in your local computer, you just write localhost to your web browser and the output of the Python application that runs a web app is displayed on your screen.
However, if you are running the Python code on a remote server, you need to access the localhost of the remote server. Normally it can‘t be accessed from outside of the local host, so how are we going to do it?
Let’s say you want to run localhost:8000
ssh -L 8000:localhost:8000 root@IPOFTHEREMOTESERVER
Now, make sure that your web app is up and running, otherwise you will get the following error every time you try to access the app that is supposed to be run on the localhost.
open failed: connect failed: Connection refused
After firing the above command, you just type localhost:8000 on your local computer and the web app running on the remote server will be displayed on the web browser of your local computer.