How to run flask python website permanently? - python

I'm following Flask Quickstart guide and can run my web app via http://myip.com:5000.
One issue is that my web is only accessible as long as I keep my SSH remote connection session - when I sleep/shutdown my PC, the website shutdown too.
How can I make it permanent available?

You need to use a regular web server, such as apache2. You can't use the python server for production purposes. Here is how you do it with apache: http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/

Related

How ToSetup a Python Flask Server in IONOS?

I have an ionos server, and I am trying to run a python flask server on it. I connected to it via a Linux Terminal with ssh, however doing python3 main.py runs it locally:
I am new to this, am I doing something wrong? I logged into the ssh with the username and password IONOS gave me in the Web Hosting Essential Page.
I connected to it with SFTP and added this python code in a file named main.py:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def home():
return "Hello, world"
app.run()
This runs it locally, but I can't figure out how to run it on my site. I think I am doing this completely wrong. I tried following the IONOS tutorials, but they don't work.
You try to access it by using a web browser in your computer:
http://your_server_ip:5000
If it can be accessed, everything is good. You can follow this tutorial to deploy it (you can choose a different version same with your version's sever near the top of the tutorial)
If it cannot be accessed, maybe your server IP is a shared IP. Ask IONOS, or use other suppliers such as digitalocean
Flask does require a server to run (apache 2 or Nginx) if you run just app.py you will launch flask server locally which is meant to be used as a way to quickly modify your server files without taking down ur web server. I highly recommend Apache2 as it’s fairly simple to use and very reliable.

Unable to access Flask app hosted on EC2 after adding https support

I have a Flask application currently using http being hosted on an ec2 instance. I want to host my application using https. Currently with http, I am able to access my application (running on 0.0.0.0 port 80) by just accessing the ec2 public IP address (displays Running on http://0.0.0.0:80/, and I am able to use my app at http://IP).
I am following this tutorial to test https support: https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https.
When I add the most basic app.run(ssl_context='adhoc') to my program, the app is now Running on https://0.0.0.0:80/, but I am unable to access my app at https://IP. I opened up my port 403 in my EC2 settings however I am still unable to communicate with my app using https...no response whenever I make a request.
The same no response occurs when I run the application with gunicorn. Am I missing something? I think my requests are well formed, however I am never able to communicate with my app when using https.
Simple way is put your instance behind ALB. ALB is not only load balancer, but also integrate ACM for free.

Flask development server blocked by proxy at work

I am trying to use the flask development server at an office with a strict proxy that blocks the default 127.0.0.1:5000 host and port. I have tried using different hosts and ports with no success. I have also tried setting up Flask with XAMPP on Windows via mod_wsgi with no success. I am looking for an option to continue testing flask on my local machine with as little setup as possible as my production environment is a PaaS and does not use the same setup as my local machine.

Running a flask server

So, probably a dumb question, but I am beginning to learn all this so your feedback will be valuable for me.
The question is: In flask documentation it says start the flask server by entering the command 'python hello.py' and I do it successfully to see the output on localhost:5000. Now, I have a shared hosting plan and if I upload this file over there will i need to initiate the server over there as well like this? If so, when I close the terminal over there, will the flask server shut down (because when I close the terminal on my computer it shuts down the flask server and the results are no more available on localhost:5000)?.. It basically suggests me that I have to keep running the terminal all the time..please tell me what is the basic idea here? Thanks.
What you're asking is how you deploy your app. There are many options, that will depend on your needs, your hosting service, etc.
You should check the flask docs for the options. http://flask.pocoo.org/docs/deploying/
In essence, you'll have your flask app running as a local service on the server, so it's not shut down when you close the terminal, and an HTTP server that somehow proxies requests to that service. I guess the most popular is uWSGI with nginx.
When you upload your code to a remote host, you will need to provide a way to start the server and get things running. How this works is host- and software-dependent. As an example, here is some documentation for how you would fire Flask up on Heroku.

Web2py unable to access internet [connection refused]

I have deployed a web2py application on a server that is running on Apache web server.
All seems to be working fine, except for the fact that the web2py modules are not able to connect to an external website.
in web2py admin page, i get the following errors :
1. Unable to check for upgrades
2. Unable to download because:
I am using web2py 1.9.9, CentOS 5
I am also behind an institute proxy. I am guessing that the issue has to do something with the proxy configurations.
Try testing the proxy theory by ssh -D tunneling to a server outside the proxy and seeing if that works for you.

Categories