How to run nginx + python (without django)
Question:
I want to have simple program in python that can process different requests (POST, GET, MULTIPART-FORMDATA). I don’t want to use a complete framework.
I basically need to be able to get GET and POST params – probably (but not necessarily) in a way similar to PHP. To get some other SERVER variables like REQUEST_URI, QUERY, etc.
I have installed nginx successfully, but I’ve failed to find a good example on how to do the rest. So a simple tutorial or any directions and ideas on how to setup nginx to run certain python process for certain virtual host would be most welcome!
Answers:
Although you can make Python run a webserver by itself with wsgiref
, I would recommend using one of the many Python webservers and/or web frameworks around. For pure and simple Python webhosting we have several options available:
If you’re looking for more features you can look at some web frameworks:
All the same you must use wsgi server, as nginx does not support fully this protocol.
You can use thttpd. It is a lightweight wsgi server for running cgi scripts. It works well with nginx. How to setup thttpd with Nginx is detailed here: http://nginxlibrary.com/running-cgi-scripts-using-thttpd/
You should look into using Flask — it’s an extremely lightweight interface to a WSGI server (werkzeug) which also includes a templating library, should you ever want to use one. But you can totally ignore it if you’d like.
I want to have simple program in python that can process different requests (POST, GET, MULTIPART-FORMDATA). I don’t want to use a complete framework.
I basically need to be able to get GET and POST params – probably (but not necessarily) in a way similar to PHP. To get some other SERVER variables like REQUEST_URI, QUERY, etc.
I have installed nginx successfully, but I’ve failed to find a good example on how to do the rest. So a simple tutorial or any directions and ideas on how to setup nginx to run certain python process for certain virtual host would be most welcome!
Although you can make Python run a webserver by itself with wsgiref
, I would recommend using one of the many Python webservers and/or web frameworks around. For pure and simple Python webhosting we have several options available:
If you’re looking for more features you can look at some web frameworks:
All the same you must use wsgi server, as nginx does not support fully this protocol.
You can use thttpd. It is a lightweight wsgi server for running cgi scripts. It works well with nginx. How to setup thttpd with Nginx is detailed here: http://nginxlibrary.com/running-cgi-scripts-using-thttpd/
You should look into using Flask — it’s an extremely lightweight interface to a WSGI server (werkzeug) which also includes a templating library, should you ever want to use one. But you can totally ignore it if you’d like.