Let's consider,
Flask app is deployed in the Server (Using proxy)
Already using 'host=0.0.0.0' & 'port=80' (or 8080 etc)
Already added '127.0.0.1 localhost' in '/etc/hosts' file.
Steps:
I have used the scp command to upload the Flask app files. And have connected to that server using 'ssh' from terminal and ran the Flask app using 'python app.py'
Flask app is running without any issue and I can see the message running on 'http://xx.xx.xx.xx:80'
Problem:
When I open the same URL in the Chrome Browser from my same local machine, it's showing "Not reachable error".
Expected:
Anybody can able to access that Flask app url (e.g http://xx.xx.xx.xx:80/home) from their local chrome browser if they are already connected to VPN on their machine.
Note: By normally I will connect to VPN in order to access that server (at the time of using SCP & SSH)
Please consider the following sample address(s):
Server - 10.xx.xx.xx
Proxy - 34.xx.xx.xx
VPN - my.abc.com (Ip Address: 9.89.xx.xx)
Browser- 173.xx.xx.xx (Chrome Browser)
Any information would be helpful, thanks!
Related
I have been banging my head against a wall trying to get my streamlit app deployed on an ec2 instance so I can share with others, however I am having trouble connecting to my streamlit app via the browser. I noticed that on my local machine I also have the same issue, when I run the streamlit app locally, I am able to access my streamlit app via local host:
http://127.0.0.1:8501/
However the "External URL" and "Network URL" do not work and the page infinitely loads and eventually times out. Here is the external url & network url given by streamlit when you run streamlit run app.py
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.
You can now view your Streamlit app in your browser.
Network URL: http://<network_ip>:8501
External URL: http://<external_ip>:8501
I can confirm that I have allowed port 8501 TCP inbound traffic on my local windows machine as well as on the ec2 instance.
Here is my security group config:
EC2 Security Group
How do I make my streamlit application accessible via the given Network URL & External URL by streamlit and not just via localhost:8501?
Would appreciate anyone's advice who has deployed a streamlit web app on an EC2 instance!
I have checked that:
My ec2 instance is listening on TCP port 8501
That the streamlit service is running by running "ps aux | grep streamlit"
Restarting my instance
So this was a bit of a face-palm moment for me, the problem I was encountering was as a result of the internal firewall blocking connections to port 8501 on my corporate network.
I'm currently running a locally hosted website, created in flask as part of a project. I wanted the server to be externally visible, so I checked the docs, and found this:
If you run the server you will notice that the server is only
accessible from your own computer, not from any other in the network.
This is the default because in debugging mode a user of the
application can execute arbitrary Python code on your computer.
If you have the debugger disabled or trust the users on your network,
you can make the server publicly available simply by adding
--host=0.0.0.0 to the command line:
$ flask run --host=0.0.0.0 This tells your operating system to listen
on all public IPs.
I assumed the same applied to python, and when started the server like this
if __name__ == "__main__":
app.debug=True
app.run(host='0.0.0.0')
When running this the terminal said Running on http://0.0.0.0:5000/, however clicking on that link just gave a "this site can't be reached" error. I tried to go the default address that it normally directed to (127.0. ...) and although this launched the site on my laptop (where flask is running) I still couldn't access the site from other devices on the same network, even when copy-pasting the url.
I also tried typing my laptops ipv4 (192.168. ...) followed by :5000 but still was unable to connect to the server.
What have I done wrong?
Run this in your terminal:
sudo ufw allow 5000
I have a project in websockets with angular and django, it works fine locally with Linux, when I have deployed it to Amazon EC2 that is also Linux and did the same with Linux locally, I have attached a screenshot of the server in django in Amazon EC2 that it looks that is running ok, server screenshot, the client that is an angular app, when I'm trying to connect to the server this.globals.socket = new WebSocket('ws://mydomain.com.com/stocks'), I'm getting this error WebSocket connection to 'ws://mydomain.com.com/stocks' failed: Error during WebSocket handshake: Unexpected response code: 404. Do I have to configure something in nginx.conf in Amazon EC2 server?, or do I have to enable something additional in the server?. Any help or clue would really be appreciated. Thank you very much.
You are running your server on localhost (127.0.0.1:8000). It's not accessible from outside. You have to run it on a public IP or configure a proxy to route requests to your localhost server. Also do not forget to open the port to the world via EC2 management interface.
Also note that you shouldn't run your server via ./manage.py runserver on production. You should use application WSGI server (e.g. Gunicorn) and webserver (e.g. Nginx). Check out this good tutorial. Basically you run Gunicorn which is bound to unix socket, and Nginx which proxies (proxy_pass) all requests to the unix socket.
I work on a project in which I need a python web server. This project is hosted on Amazon EC2 (ubuntu).
I have made two unsuccessful attempts so far:
run python -m SimpleHTTPServer 8080. It works if I launch a browser on the EC2 instance and head to localhost:8080 or <ec2-public-IP>:8080. However I can't access the server from a browser on a remote machine (using <ec2-public-IP>:8080).
create a python class which allows me to specify both the IP address and port to serve files. Same problem as 1.
There are several questions on SO concerning Python web server on EC2, but none seems to answer my question: what should I do in order to access the python web server remotely ?
One more point: I don't want to use a Python web framework (Django or anything else): I'll use the web server to build a kind of REST API, not for serving HTML content.
you should open the 8080 port and ip limitation in security croups, such as:
All TCP TCP 0 - 65535 0.0.0.0/0
the last item means this server will accept every request from any ip and port, you also
You passble need to IAM in AWS.
Aws set security permission that need to open up port so you only localhost links your webservice
aws link
With the help of the post Flask - configure dev server to be visible across the network, I have tried the same to make my Flask externally visible so that I can send HTTP requests from my local browser to the Flask in remote server.
Can someone please help on why its not working for me even I have opened the connections.
I started my flask in Putty [script in dev server] and tried accessing the URL from my Chrome as http://[my_sys_ip]:5000/. Chrome reports me OOPS error.
On Flask, I have made it externally visble with debug mode turned off:
if __name__ == '__main__':
app.run(host='0.0.0.0', debug = False)
From netstat, I can see its listening on 5000:
netstat -an | grep :5000
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN
When tried to send a GET request from the same dev server, I'm successful with the expected response:
python testing.py
URL called is http://0.0.0.0:5000/
Message to the user is Hello World!!!!!!!
What am I missing ?
I know this is an old question, but I figured I'll throw my 2 cents in.
From your description, it sounds like you are launching your flask application on a remote server (dev server) through PuTTY. You are then trying to access the app on your local system (localhost). The application isn't running on your local system, so that would explain the error in chrome.
Instead of going to http://[my_sys_ip]:5000, you will need to go to http://[dev_svr_ip]:5000.