difference between uwsgi module in nginx and uwsgi

2019-02-13 09:06发布

问题:

I'm new to linux development. I'm a bit confused on the documentation i read. My ultimate goal is to host a simple python backed web service that would examine an incoming payload, and forward it to other server. This should be less than 30 lines of code in python.

I'm planning to use nginx to serve up python file. From my research, i also need a python web framework. I chose to go with uwsgi. I'm so confused. which one do I need? an nginx uwsgi module, or uwsgi server? i don't want to put django just for this simple purpose.

the nginx documentation mention that

Do not confuse the uwsgi protocol with the uWSGI server (that speaks the uwsgi protocol)

So, does that mean, i don't need to install uwsgi server separately? do i just install nginx, and start configuring? I'm using nginx 1.4.4

Could someone share a step by step configuration procedure on how to configure uwsgi with nginx, along with a sample python code(hello world maybe)? i can configure nginx just fine, but i don't know how to make it serve python pages. all the docs i could find involves having django on top.

回答1:

You're mixing up things, so let me clarify.

Python's standard way of publishing applications via web servers is WSGI--you can think of it as a Python's native CGI. uWSGI is a WSGI-compliant server that uses uwsgi protocol to talk to other uWSGI instances or upstream servers. Usually the upstream server is nginx with HttpUwsgiModule that allows it to communicate using uwsgi protocol--with nginx you have additional layer of protection for your app server, load balancing and serving the static files. In most scenarios, You Should Be Using Nginx + UWSGI. To answer your question, uWSGI is installed and run separately from nginx, and they both need to be configured to communicate to each other.

Pure WSGI is pretty low-level, so you may want to use a WSGI-compliant framework. I guess the top two are Django and Flask.

For a hello world Flask setup, Serving Flask With Nginx seems to be a good article.