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!
In the diagram, a Python application server fits into the Application server block in the backend, and is shown being accessed by FastCGI. NGINX doesn’t “know” how to run Python, so it needs a gateway to an environment that does. FastCGI is a widely used interface for PHP, Python, and other languages.
Gunicorn will have to be running to enable communication between nginx and django project. First, we’ll use just gunicornto display our django test project on 127.0.0.1:8000. It’s incredibly easy. Again - assure yourself you are working in current virtualenv. Now navigate yourself inside /var/www/test/ourcase/and run this magical command:
Gunicorn can make serversimilar to django test server. But it can also servedjango app content to nginxand hence solving nginx’s limitation. Third layer (django)¶ Then there is just django- your project with you pages - this is what your website is about.
Nowadays Django is becoming more powerful in designing web applications. Running a local server of Django is not a recommended way in production because it’s just a test server not a production ready server. So to run Django in production is to run with Gunicorn and use Nginx as a reverse proxy so it gives more security to our application.
Although you can make Python run a webserver by itself with wsgiref
, I would recommend using one of the many Python webservers around.
In the case of Nginx I would look at Gunicorn or uWSGI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With