0

According to official uWSGI docs : A web server faces the outside world. It can serve files (HTML, images, CSS, etc) directly from the file system. However, it can’t talk directly to Django applications; it needs something that will run the application, feed it requests from web clients (such as browsers) and return responses.

A Web Server Gateway Interface - WSGI - does this job. WSGI is a Python standard.uWSGI is a WSGI implementation.

Does it mean that uWSGI is a must if I want to deploy a Django application on web server ?

1 Answer 1

1

Short answer: you need some form of seperate django server, yes.

Long answer: nginx itself can only serve static files. It can read any file on your server and send it out via HTTP, but that is it. It does not speak PHP, Python, Java, ... by itself. If you would point nginx to a python file, it would just treat it as a text file and display the source code, because it does not know what else to do with it.

Dynamic websites work like this:

  1. request arrives at web server
  2. web server forwards the request to a PHP/Python/etc application server
  3. app server generates HTML from request
  4. app server sends HTML to web server
  5. web server serves HTML

For point 2 to work, you need to 'teach' nginx to treat certain files/urls differently. You basically tell it that everything ending in .php should be forwarded to the php server. The same is true for django apps. You need to tell nginx to forward certain URL patterns to a django server, which then runs the python scrpts to generate the HTML.

uWSGI is one Django server, but there are multiple ones.

4
  • Thanks.. But the django framework itself comes with a server. Then why would i need uWSGI for that? May 27, 2016 at 16:19
  • If you are talking about http.server, it is not a fully fledged server, and not as performant or secure as an actual, purpose-written, heavily optimized, server.
    – mzhaase
    May 27, 2016 at 16:21
  • Ok understood.. But one last question.. Will uwsgi alone suffice.. If it is optimized then can i throw away the nginix layer? May 27, 2016 at 16:23
  • No. uwsgi just generates the HTML, you still need an http server.
    – mzhaase
    May 31, 2016 at 10:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .