What is the purpose of using nginx with a gun?

I want to use gunicorn for a restapi jar / python application. What is the purpose of adding nginx here to guns? On the site of hunting weapons, it is recommended to use guns with nginx.

+5
source share
6 answers

Here is a satisfactory quoted answer that I came across when I was NOT trying to find a satisfactory answer. Basically, I found out that Gunicorn is not intended for a full-fledged web server, but there is nginx.

... Wait, why do we need two servers? Think of Gunicorn as an application web server that will run for nginx, a front-oriented web server. Gunicorn is compatible with WSGI. It can talk with other applications supporting WSGI, for example Flask or Django.

Source: https://realpython.com/blog/python/kickstarting-flask-on-ubuntu-setup-and-deployment/

+3
source

No matter which application server you use (Gunicorn, mod_wsgi, mod_uwsgi, cherrypy), any non-trivial deployment will have something at the top that will handle requests that your Django application should not handle. Trivial examples of such queries are for static resources (images / css / js).

This leads to the first two levels of the classic "three-tier architecture." That is, the web server (Nginx in your case) will handle many requests for images and static resources. Requests that should be dynamically generated are then sent to the application server (Gunicorn in your example). (Aside, the third of three levels is the database)

Historically, each of these levels will be hosted on separate machines (and in the first two levels, most likely there will be several machines, that is: 5 web servers send requests to two application servers, which, in turn, request one database).

In the modern era, we now have applications of all shapes and sizes. Not every weekend or small business project actually needs the horsepower of several cars and will work quite happily on one box. This led to the emergence of new entries in the array of hosting solutions. Some solutions will go beyond the application server to the web server (Apache httpd + mod_wsgi, Nginx + mod_uwsgi, etc.). And it’s not at all uncommon to place a database on the same computer as one of these server / application combinations.

Now, in the case of Gunicorn, we made a specific decision (copying from Ruby Unicorn) to separate things from Nginx, relying on the Nginx proxy behavior. In particular, if we can assume that Gunicorn will never read connections directly from the Internet, then we need not worry about slow clients. This means that the processing model for Gunicorn is awkwardly simple.

Separation also allows you to write Gunicorn in pure Python, which minimizes development costs without significantly affecting performance. It also allows users to use other proxies (provided they are buffered correctly).

As for your second question about what actually handles the HTTP request, the simple answer is Gunicorn. Full answer: Nginx and Gunicorn process the request. Basically, Nginx will receive the request, and if it is a dynamic request (usually based on URL patterns), then it will provide this request to Gunicorn, which will process it, and then return a Nginx response, which then redirects the response back to the original client.

So in conclusion, yes. For proper Django / flask deployment, you need both Nginx and Gunicorn (or something similar). If you specifically want to host Django / flask with Nginx, I would examine Gunicorn, mod_uwsgi, and possibly CherryPy as candidates for the Django / flask side.

Renouncement

+3
source

Nginx is a reverse proxy for Gunicorn. Gunicorn serves your flash application, and Nage sits in front of him and decides where the request should go. For example, if the incoming request is an HTTP request, Nginx redirects it to gunicorn, if it is intended for a static file, it serves it itself. Learn more about how to use Nginx ang Gunicorn and how to deploy them, starting from here: http://rahmonov.me/posts/run-a-django-app-with-gunicorn-in-ubuntu-16-04/

+2
source

Do you know why Django's mascot is a pony? The story is that Django comes with as many things you want: ORM, all kinds of middleware, admin site ... "What else do you want, pony?" Well, Gunicorn means "Green Unicorn" - obeythetestinggoat.com

  • Nginx is the front side of your server.
  • Gunicorn runs several django projects (each project is a wsgi Gunicorn-based application) on a single server (for example, Ubuntu).

Each request comes to nginx and asks which application to dismiss if it passes, and it redirects it.

NOTE - Gunicorn cannot execute static files automatically, as your local django server does. So you will need nginx for this again.

+1
source

During production, nginx acts as a reverse proxy. This means that users will hit nginx from the browser, and nginx will redirect the call to your application. Hope this helps.

0
source

Gunicorn is an application server for launching your python application instance.

NGINX is a reverse proxy. He accepts incoming connections and decides where they should go next. He is in front of the Gunicorn.

0
source

Source: https://habr.com/ru/post/1265952/


All Articles