Reputation: 605
I have server on an external hardware running at port number 162.74.90.100
and i can access all the files and terminal on it using SSH Secure Shell software.
Now i run a Python-Flask server (127.0.0.1:5000
) on the existing server (ie. 162.74.90.100
) which is supposed to run a website.
To access the website, I tried running the IP addresses in a browser like 162.74.90.100/127.0.0.1:5000
but it does not work.
can anyone suggest how can I access 127.0.0.1:5000
using browser? I am stuck and cannot find any relevant documentation.
Upvotes: 0
Views: 3564
Reputation: 1122222
You can't, not directly. By running on 127.0.0.1 (localhost), you are explicitly not binding to a public IP address and are not visible to the outside world.
Your options are to:
Use SSH port forwarding to redirect traffic from your own machine to that localhost port; add -L 5000:localhost:5000
to your ssh
command line and access the Flask server at http://localhost:5000
. Use this option if only you should be able to access the server.
Use a 3rd party service like ngrok to tunnel from a public host to your Flask server.
Use another web server serving on a public IP address forwarding connections to localhost:5000. See Proxy Setups in the Flask deployment documentation.
Restart the Flask server to bind to a public IP address, not 127.0.0.1. This is not recommended, as the development web server that comes bundled with Flask is not really suited for the rough world that is the public internet. You can do this by giving app.run()
a host
argument:
app.run(host='162.74.90.100')
or (using the flask
command-line tool) using the --host
command-line argument:
flask run --host 162.74.90.100
to bind to your public IP address, or use 0.0.0.0
to bind to all available IP addresses on your server. This will only work if your server is connected directly to the internet (not behind a router) and the firewall allows connections to the port; you'll need to configure the router and firewall otherwise.
Upvotes: 3
Reputation: 21
The reason why you are not able access your application is because you are not running it off the interface(162.74.90.100, in your case) where you need to access it from.
Since you are using a flask application, and I am assuming your run code looks something like this...
if __name__ == '__main__':
app.run()
This would by default associate your application to the localhost(127.0.0.1) at port 5000. Now for the application to run on port 5000 exposed to outside world you either do this....
if __name__ == '__main__':
app.run(host='162.74.90.100')
or this...
if __name__ == '__main__':
app.run(host='0.0.0.0')
I would suggest latter which runs the application off all the interfaces, hence being accessible from the outside world. Once you have made this change, you could access your application at 162.74.90.100:5000
Upvotes: 2