Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run nginx + python (without django)

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!

like image 503
ddinchev Avatar asked May 02 '12 10:05

ddinchev


People also ask

Can I run a python application on nginx?

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.

How to enable communication between Nginx and Django project?

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:

Is Gunicorn a good alternative to Nginx?

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.

How to run Django on Gunicorn?

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.


1 Answers

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.

like image 181
Wolph Avatar answered Oct 29 '22 10:10

Wolph