Why combining flask with apache2 server is better? - python

A recent flask application I wrote needed to be on an apache2 server. I successfully completed connecting apache and flask but I still wonder why using apache and wsgi is better than just saying "python main.py" and just running the server on port 8080 with port 80 forwarding to 8080?

If you run your sever directly with python on a port, using Flask, then the server will be single threaded with your requests. Your performance will suffer.
How many concurrent requests does a single Flask process receive?

Related

GUNICORN FastAPI Deployment with Proxy

I am currently setting up a FastAPI application to run on an AWS RockyLinux 8 instance with a gunicorn deployment. Most of the documentation that I have read recommends NGINX as a proxy server.
I currently have an Apache sever running on this instance and would rather not install another HTTP daemon if I can help it.
My question is: Why is a proxy HTTP server needed at all? gunicorn seems to run just fine without a proxy HTTP server simply by specifying a port other than 80. Is this a security recommendation or am I missing something?

Running WSGI web server on a port (without using IIS)

Opening up a port for http request using WSGI (code is in Python+Django) on windows 10 - does not work for http requests coming from another machine
I have a python+django+mongodb site which works great when I run it through VS and now I would like to publish it.
My IIS set up with web.config with fastCGI gone bonkers and I am too frustrated to pursue it for the time being.
Now I decided to run a WSGI server on a port. So here is what I did. I started my app from command line by running my manage.py like this...
C:\Users\<myname>\AppData\Local\Continuum\anaconda3\python.exe manage.py runserver --noreload --settings=myapp.settings
And it starts the server and I can visit the site at http://localhost:8000 and everything works great - LOCALLY.
But with my machine IP x.y.z.w - I cannot access it from another machine
by visiting http://x.y.z.w:8000
Why can't my server listens to the port 8000 from another machine on the SAME network?
What do I have to do to allow this?
I am on Windows 10

Why does Flask use port 5000 locally and 80 when deployed?

I have been testing my Flask app locally and then deploying it on an AWS EC2 instance. Where is the default port defined? If I don't specify any port, it uses port 5000 locally; when deployed it uses port 80. Is it defined in the Flask code or is it part of the web server settings?
Flask's (Werkzeug's) dev server defaults to port 5000 if no port is specified. This is because binding to ports below 1024 requires elevated permissions.
You are not (or if you are, you shouldn't be) using the dev server in production, you're using a real WSGI server and HTTP server, such as uWSGI and Nginx, or Amazon's WSGI handler. The web server, independent of Flask, binds to port 80.

Running Flask with Gunicorn On Raspberry Pie

I'm trying to run my flask app with gunicorn on my Raspberry pi. I've set up my router to port forward the localhost:5000. This works well when I run my flask app via python manage.py runserver. I can use my browser from any device and type http://**.**.***.***:5000/ and it will load my flask application. However when I try and run the app via gunicorn I receive an error connecting page. I run the the gunicorn exactly like the flask documentation says to. If I check gunicorn's logs I can see the html being rendered. Here's the kicker, when I run the app with gunicorn locally (gunicorn -w 2 -b localhost:5000 my_app:app), it works just fine. I have optimum online, my router setting are as followed...
protocol -> all
port -> 5000
forward port to -> same as incoming port
host -> raspberrypi
locate device by -> ipaddress
Like I said these settings work just fine from my pi when I use python's built in wsgi server. Gunicorn works just fine on when I run it locally and I can see my app when I type localhost:5000 in the browser, it's just when I set it up on my pi and try to access the page with the external IP, if I don't use gunicorn the external IP works just fine. I can't figure it out. Any ideas?
You need to have Gunicorn listen on 0.0.0.0 (all network interfaces). This then means it will be listening on an externally accessible IP address.
There is more information on the difference between localhost and 0.0.0.0 in this post on ServerFault.

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.

Categories