Binding is still done on the default flask port 5000.ĭescription=Gunicorn instance to serve app
This is constructed as the name of the module, plus the name of the callable within the application. We can do this by simply passing it the name of our entry point. We need to bind this to the Gunicorn server so that Gunicorn can serve our application. Set up Gunicorn: what we have after step 1 is a flask application and a WSGI server script ( manage.py). Once you have a Flask app running locally, to put it in production you have toĬonfigure a WSGI entry point: done in the manage.py file Only requests which are meant to arrive at the application are passed on toward the application server (Gunicorn) and the application itself (Flask). Roughly speaking, these components are collated together as follows: the web server (Nginx) accepts requests, takes care of general domain logic, and takes care of handling https connections. In our implementation, we will use Nginx as a reverse proxy server. The reverse proxy directs all the requests from the clients to the servers and it also delivers all the responses from the servers to the clients. In a computer network, a reverse proxy sits between a group of servers and the clients who want to use them. Nginx and Apache are the two best web servers to host a web application. It is known for its stability, rich feature set, simple configuration, and low resource consumption. It also serves the purpose of reverse proxy, as well as an IMAP/POP3 proxy server. The Nginx front-end reverse proxy: Nginx is a free, open-source, high-performance HTTP server. A Gunicorn (WSGI) server is a must when an application is deployed in production. Gunicorns run multiple instances of your web application, making sure that they are healthy and restart them whenever needed, distributing incoming requests across those instances, and communicate with the webserver. Gunicorn takes care of everything which happens in-between the web server and your web application. It also does not care what you used to build your web application - as long as it can be interacted with using the WSGI interface. Gunicorn is built so that many different web servers can interact with it. The Gunicorn application server: Gunicorn is a WSGI server. Load balancing and remote processing, by forwarding requests and responses over a network. Routing a request to different application objects based on the target URL, after changing the environment variables accordingly.Īllowing multiple applications or frameworks to run side-by-side in the same process. A WSGI component can perform functions like:
A WSGI middleware component is a Python callable that is itself a WSGI application - Gunicorn in our case. It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request. *WSGI is the Web Server Gateway Interface. If you want to learn Flask, you must check out this amazing mega-tutorial It is a microframework designed to get started quickly and easily, with the ability to scale up to complex applications. It provides you with tools, libraries, and technologies that allow you to build a web service. The Flask app: Flask is a simple, lightweight WSGI* web application framework.
This web-app is composed by 3 core components: But the good news is we can tools that take care of them. One will have to carry out the following tasks: (i) handle static files if present, (ii) handle https connections, (iii) recover from crashes, (iv) make sure your application can scale up to serve multiple requests. Imagine hosting or deploying multiple web applications in production. This will spawn a container, start serving the flask app at localhost:8787.