Welcome! Log In Create A New Profile

Advanced

nginx + python

Posted by klompie 
nginx + python
June 08, 2012 07:52AM
What is the best way to setup nginx to handle python.
I am tring to setup a nginx server that can have multiple python backends, but cant get it to work.

It just gives me an error like:
uWSGI Error
Python application not found

On my backends i installed uwsgi, but because the nginx installation does not have the uwsgi module enable (and i cannot change that) i configured uwsgi to use fastcgi.

This is my uwsgi.ini used to start uwsgi (uwsgi --ini uwsgi.ini)
--------------------------------------------------------------------------------------------------------------------------------
[uwsgi]
# set the http port
socket = :9000

# change to directory
chdir = /var/cache/cpsagent/www

#write pid to file
pidfile = /var/cache/cpsagent/uwsgi.pid

#logfile
daemonize = /var/cache/cpsagent/uwsgi.log

#use fastcgi because nginx does not support uwsgi
protocol = fastcgi

master = true
--------------------------------------------------------------------------------------------------------------------------------


My nginx config is as follows. Currently configured for one backend
--------------------------------------------------------------------------------------------------------------------------------

user www-data;
worker_processes 1;

error_log /var/cache/cpsagent/nginx-proxy-error.log;
pid /var/run/cpsagent/nginx-proxy.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
access_log /var/cache/cpsagent/nginx-proxy-access.log;
sendfile on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
port_in_redirect off;
index index.html index.htm ;
error_page 403 = @forbidden;
error_page 404 = @notfound;
error_page 500 = @internalerror;

upstream web_upstream {
server 50.16.135.74:8080;
}

upstream uwsgi_upstream {
server 50.16.135.74:9000;
}

server {
listen 80 default;
root /var/cache/cpsagent/www/code-6eW2ao;
location / {
proxy_set_header Host code-6eW2ao;
proxy_set_header X-Real-IP $remote_addr;
proxy_intercept_errors on;
if ( -f $request_filename ) {
proxy_pass http://web_upstream;
break;
}
if ( -f $request_filename/index.html ) {
rewrite ^(.*)$ $1/index.html last;
}
}
location ~ \.py$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME code-6eW2ao/$fastcgi_script_name;
fastcgi_param SERVER_NAME $host;
fastcgi_intercept_errors off;
fastcgi_pass uwsgi_upstream;
}
location @forbidden {
}
location @notfound {
}
location @internalerror {
}
}
}

--------------------------------------------------------------------------------------------------------------------------------
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 157
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready