Why does Nginx need to be used when Gunicorn or uWSGI is used?

Source: Internet
Author: User
Tags keep alive
If only one machine is used, why does Nginx need to be added before Gunicorn or uWSGI? In what scenarios can we improve performance? If only one machine is used, why does Nginx need to be added before Gunicorn or uWSGI? In what scenarios can we improve performance? Reply content: in one case, there are multiple local web Services written in Python, php, and java, all of which want to listen to port 80, at this time, there must be a service responsible for forwarding.

If the local machine is sure to only run this service, but uwsgi and gevent are not very good at processing static resources, one is performance problems, and the other is various HTTP request cache headers, the processing is not complete with Nginx.

Then there are some security issues. As a professional server, Nginx is relatively safe to be exposed to the public network (although there is a well-known painstaking vulnerability). If uwsgi and gevent are used, the vulnerability may only be more than Nginx.

The supported protocols. In the early days, uwsgi and gunicon did not support https. They only provided http for browser access. Although both of them are supported now, I am afraid nginx will be faster in the future for spdy and http2.

There are also some O & M advantages, such as CC attacks on the server. This is a very common situation. nginx can easily add some IP addresses to the blacklist and directly change the configuration file. If it is uwsgi or gunicorn, I am afraid I have to modify the code of my application and write the IP address filter.

The subject said that only a single machine is considered, but if not, then an nginx Server Load balancer is almost necessary. Answer your questions.

First, the answers from anonymous users are comprehensive. Thank you.

I checked the information and found a good answer. Django-Why do I need nginx when I have uWSGI

Based on the above content, we will summarize the following:
  • More secure Nginx
  • Nginx can better process static resources (through some http request headers)
  • Nginx can also cache some dynamic content
  • Nginx can better work with CDN
  • Nginx supports load balancing among multiple machines
  • You do not need to process keep alive on the wsgi server.
  • Let Nginx handle slow client
  • Another more concealed difference is that, for example, uWSGI supports wsgi and Nginx supports http.

In a word, if the traffic volume is small, there is no need to add Nginx. uWSGI or Gunicorn is sufficient. 1. nginx is superior to uwsgi (Gunicorn) in processing static files and has better performance.

If there is no static file, or the static file is processed by another server, nginx is not needed. It is very dangerous to expose Gunicorn directly. In addition, Nginx also has many convenient routing functions, which are suitable for front-end blocking.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.