How to run flask project in remote computer server? (windows) [duplicate] - python

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 2 years ago.
I uploaded a Flask project that I prepared to a server of a windows computer. I can run the project over localhost on the computer I connect remotely. But I was asked to access the project from any computer with the IP and port address of the remote computer. What should I do for it?

You need to tell flask to run on all interfaces, either with:
flask run -h 0.0.0.0
Or if you're launching via app.run, provide the host argument:
if __name__ == '__main__':
app.run(host='0.0.0.0')
Of course if your machine has several interfaces, you could provide the IP of the specific interface instead of 0.0.0.0.
Bear in mind that the dev server is not meant for production. The above is fine if you want to access you're dev server remotely, but you'll probably want to run with something like gunicorn eventually, in which case provide the IP:port combo as the bind flag:
gunicorn --bind 0.0.0.0:5000 app:app

Related

How to access flask application outside terminal? [duplicate]

This question already has answers here:
Configure Flask dev server to be visible across the network
(17 answers)
Closed 1 year ago.
I am trying to run simple hello world flask application. I followed all the steps mentioned here as I am using Ubuntu 18.04.5 LTS.
When I execute command flask run, I got following output:
But I am not able to get application run even after visiting the address http://10.142.0.2:5000. Tried using another IP address as well.
Opened port 5000, but not able to see in the list of open ports. Tried setting new firewall rule through GCP console as well.
If you are connecting via ssh you can use Gunicorn with nginx as a server. Note: They are running in the background(you can use the terminal when they are running.)
If you are trying to remove the port number you can change the port as 80
Are you trying to access your web app from another machine? That won't work because 127.0.0.1 means localhost. Try
flask run --host=0.0.0.0
This will tell flask to listen on all interfaces and not only the loopback address.
See https://flask.palletsprojects.com/en/latest/quickstart/#public-server for details.

Quick way to run flask on 0.0.0.0:80 in company's intranet [duplicate]

This question already has answers here:
Configure Flask dev server to be visible across the network
(17 answers)
Closed 3 years ago.
I am noticing that the Flask default server should not be used for the production server.
However, in my case, I just want to share a prototype web application created by Flask in the company's intranet using port80.
I tried to specify port referring to stackoverflow page by the following code.
if __name__ == "__main__":
app.run(host='0.0.0.0',port=80)
But they still run on 127.0.0.1:5000. (refer to screen capture of command prompt)
Does anyone know what I should revise in order to run the flask application using port 80?
Please try to run it with
python <yourfile>.py
flask run might be a cause of your problem
As mentioned in the Documentation, flask run will run the development server on 127.0.0.1:5000 and ignore your app.run:
The run command will start the development server. It replaces the Flask.run() method in most cases.
https://flask.palletsprojects.com/en/1.0.x/cli/#run-the-development-server
So instead of using flask run just execute your script directly with Python.
The correct way to launch this using flask run is by specifying the -h flag:
flask run -h 0.0.0.0

How can I access my Gunicorn served Flask app from the web? [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Configure Flask dev server to be visible across the network
(17 answers)
Django site not accessible after gunicorn started
(1 answer)
Closed 4 years ago.
Regarding the following documentation:
Gunicorn¶ Gunicorn ‘Green Unicorn’ is a WSGI HTTP Server for UNIX.
It’s a pre-fork worker model ported from Ruby’s Unicorn project. It
supports both eventlet and greenlet. Running a Flask application on
this server is quite simple: gunicorn myproject:app Gunicorn provides
many command-line options – see gunicorn -h. For example, to run a
Flask application with 4 worker processes (-w 4) binding to localhost
port 4000 (-b 127.0.0.1:4000):
gunicorn -w 4 -b 127.0.0.1:4000 myproject:app
This is all and well, however, the documentation does not say how to configure port 4000 to be accessible from the web.
I want to be able to handshake something like the following,
www.mysite.com:4000
And get back a response.
My app works fine on Flask’s development server and Gunicorn locally. I just can’t figure out how to configure it to work on my cloud instance so I can make posts and gets.
You are not supposed to make gunicorn available over the web. Instead you are supposed to use it with a reverse proxy, such as nginx.
The gunicorn docs have a full example of configuring nginx to reverse proxy to your gunicorn process.

Can't access Django development server remotely [duplicate]

This question already has answers here:
Connecting to EC2 Django development Server
(6 answers)
Closed 6 years ago.
After reading this post on Stack Overflow, I cannot gain access to the files on my AWS EC2 Ubuntu instance by running the Django development server. Obviously this server would not be used in production but I want to use it for testing purposes and to check that my Django project is configured correctly.
I tried:
python manage.py runserver 0.0.0.0:8000
sudo python manage.py runserver 0.0.0.0:8000
python manage.py runserver 172.31.19.247:8000 (local IP for EC2 instance)
All of these run the development server in the console with no errors. The only problem is, I still can't access it!
How can I access my Django development server?
Ideally, I want to be able to access it through the public IP of the EC2 instance.
You need to make sure port 8000 is added as a Custom TCP Rule into your Security Group list of inbound ports.

Run web server locally without exposing it publicly? [duplicate]

This question already has answers here:
How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?
(3 answers)
Closed 8 years ago.
I am running a dedicated server on Digital Ocean. My site uses Flask on NGINX through Gunicorn. During development I plopped a search engine (solr) on a local VM (through VMWare Fusion) which happens to be running Tomcat. It could have been running any web server per my question. In my app I make all search requests to that local ip: 192.168.1.5. Now, when I install Tomcat on my server and run it you can see it publicly at mysite.com:8080. There's the old welcome screen of Tomcat for the world to see. I want my app to be able to access it locally through localhost:8080 but not show it to the world. Is this possible?
The short answer is no.
While using a hosting plan, so actually anything that you are doing is 'exposed to the world' since you yourself have to access it remotely, like everyone else.
You have two options, the first, configure the Digital Ocean server to only accept connections from your public IP, and the second, keep using your development server locally until you are ready for primetime.

Categories