How to run nginx + python (without django)

I want to have a simple python program that can handle various requests (POST, GET, MULTIPART-FORMDATA). I do not want to use the full structure.

I basically need to be able to get the GET and POST parameters - perhaps (but not necessarily) in a way similar to PHP. To get some other SERVER variables like REQUEST_URI, QUERY, etc.

I installed nginx successfully, but I could not find a good example of how to do the rest. Therefore, a simple tutorial or any directions and ideas on how to configure nginx to run a specific python process for a specific virtual host is very welcome!

+7
source share
4 answers

You should study the use of Flask, which is a very lightweight interface for the WSGI server (werkzeug), which also includes a template library if you ever want to use it. But you can completely ignore him if you want.

+4
source

Although you can get Python to run the wsgiref web server yourself, I would recommend using one of the many Python web servers around.

In the case of Nginx, I would look at Gunicorn or uWSGI.

+8
source

You can use thttpd. This is a lightweight wsgi server for running cgi scripts. It works well with nginx. How to configure thttpd with Nginx is described in detail here: http://nginxlibrary.com/running-cgi-scripts-using-thttpd/

+1
source

You should still use the wsgi server, since nginx does not fully support this protocol.

0
source

All Articles