nginx gunicorn - PuZheng/PuZheng-Docs GitHub Wiki

http://gunicorn.org/ is a speedy wsgi http server, and it is better to lay behind nginx (as the load balancer).

first, let us start gunicorn.

$ gunicorn myapp:app -b ip:port

then configure nginx to add a site:


# only need when load balancing
upstream myapp_server {
	server ip:port;
}

server {
	listen 10001;
	
	location / {
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $http_host;
		proxy_redirect off;
		proxy_pass http://myapp_server;
        # if not load balancing
        # proxy_pass http://ip:port
	}        
}

restart nginx, done.