Running Flask application without nginx or other web server?
Can uWSGI be a web-server and application server at the same time?
For example, stand-alone WSGI Containers https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/ But again, it recommends to use an HTTP server. Why? Can't uWSGI handle HTTP requests?
I have read different articles about deploying a Flask application. They say, I'd need uWSGI and nginx - one popular option.
https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
https://flask.palletsprojects.com/en/1.1.x/deploying/uwsgi/#uwsgi
My Flask application. app_service.py
import json
import os
from flask import Flask, Response, redirect
portToUse = 9401
@app.route("/app/people")
def get_service_people():
print("Get people")
people_str = "{ \"John\", \"Alex\" }"
return Response(people_str, mimetype="application/json;charset=UTF-8")
if __name__ == "__main__":
app.run(host='0.0.0.0', port=portToUse)
uwsgi config uwsgi.ini
[uwsgi]
chdir = $(APPDIR)
wsgi-file = app_service.py
callable = app
uid = psc-user
gid = psc-user
master = true
processes = 1
threads = 1
http-timeout = 300
socket-timeout = 300
harakiri = 300
http = 0.0.0.0:9401
socket = /tmp/uwsgi.socket
chmod-sock = 664
vacuum = true
die-on-term = true
; Images serving: https://github.com/unbit/uwsgi/issues/1126#issuecomment-166687767
wsgi-disable-file-wrapper = true
log-date = %%Y-%%m-%%d %%H:%%M:%%S
logformat-strftime = true
logformat = %(ftime) | uWSGI | %(addr) (%(proto) %(status)) | %(method) %(uri) | %(pid):%(wid) | Returned %(size) bytes in %(msecs) ms to %(uagent)
requirements.txt
# Web framework for python app.
Flask==1.1.1
# JWT tocket utils to retrieve the tocken from HTTP request header.
# It is used for retrieving optional permissions from gateway.
# https://pypi.org/project/PyJWT/
PyJWT==1.7.1
# Eureka API client library to implement service discovery pattern
py_eureka_client==0.7.4
# Python application server
uWSGI==2.0.18
And it seems to be working. I am running all this in a virtual machine in docker-compose.
My question, why do I need nginx here? Do python developers use uWSGI without a web server?
Update
I am not going to run dev default WSGI server in production, as it is asked here Are a WSGI server and HTTP server required to serve a Flask app?
WSGI servers happen to have HTTP servers but they will not be as good as a dedicated production HTTP server (Nginx, Apache, etc.)
from https://stackoverflow.com/a/38982989/1839360
Why is it so?
What I am asking is why uWSGI server cannot be as good for HTTP handling, so I need to put HTTP server between the internet and uWSGI there. Why incoming HTTP requests can go directly to uWSGI (it is not running in the development or debug mode).