Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx uwsgi and cgi python script

I've run into issue. I have a python script. You can call it CGI script. It works fine under Apache2, but is only one left before I shutdown system it runs forever. New system uses nginx. I've configured uwsgi as suggested by many while searching on solution, configured virtual host for this script to run. I've used first example on uwsgi wiki to confirm I have properly configured nginx and it can communicate with uwsgi. Worked like charm.

Now my complications:

My script was written some time ago and is not designed for WSGI, nor I want/can rewrite it.

So I've installed cgi module for uwsgi and tried using it. All I get is 502 errors. Nothing being executed uwsgi.

Here is my config I'm using for this app:

[uwsgi]
plugins = cgi
socket = 127.0.0.1:9010
cgi = /=/usr/share/test/
cgi-allowed-ext = .py
cgi-helper = .py=python

Here is code I have in index.py (test script):

#!/usr/bin/python
print "Content-type: text/html\n\n"
print "<html><body><h1>It works!</h1></body></html>"

I try to test uwsgi with following command:

/usr/sbin/uwsgi --http :9011 --ini /etc/uwsgi/test.ini --master

And here is output I get:

[uWSGI] getting INI configuration from /etc/uwsgi/test.ini
*** Starting uWSGI 1.1.2 (64bit) on [Fri Apr 20 15:26:33 2012] ***
compiled with version: 4.4.6 20110731 (Red Hat 4.4.6-3) on 19 April 2012 15:09:37
current working directory: /home/user
detected binary path: /usr/sbin/uwsgi
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread mutexes
uWSGI http bound on :9011 fd 3
uwsgi socket 0 bound to TCP address 127.0.0.1:9010 fd 6
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
initialized CGI mountpoint: / = /usr/share/test/
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 6727)
spawned uWSGI worker 1 (pid: 6728, cores: 1)
spawned uWSGI http 1 (pid: 6729)
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --
-- unavailable modifier requested: 0 --

Where is problem? Please help.

Thanks in advance.

like image 581
sashk Avatar asked Apr 20 '12 19:04

sashk


People also ask

Does nginx support CGI?

Nginx doesn't have native CGI support (it supports fastCGI instead). The typical solution for this is to run your Perl script as a fastCGI process and edit the nginx config file to re-direct requests to the fastCGI process. This is quite a complex solution if all you want to do is run a CGI script.

What is the difference between Nginx and uWSGI?

Nginx is “a web server which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache”. uWSGI is an implementation of the WSGI spec, which describes how a web server should communicate with a web app, which makes uWSGI also a type of web server.

Is Nginx a uWSGI?

Nginx natively includes support for upstream serversupstream serversIn computer networking, upstream server refers to a server that provides service to another server. In other words, upstream server is a server that is located higher in a hierarchy of servers.https://en.wikipedia.org › wiki › Upstream_serverUpstream server - Wikipedia speaking the uwsgi protocol since version 0.8.


1 Answers

Ok. I didn't read uwsgi WIKI good enough. All I had to do, is add --http-modifier1 9 to the command line switch, or uwsgi_modifier1 9; to nginx config.

location / {
     include /etc/nginx/uwsgi_params;
     uwsgi_modifier1 9;
     uwsgi_pass 127.0.0.1:9010;
}

/usr/sbin/uwsgi --http :9011 --http-modifier1 9 --ini /etc/uwsgi/test.ini --master
like image 129
sashk Avatar answered Nov 14 '22 21:11

sashk