您的位置:首页 > 运维架构 > Nginx

nginx + uwsgi+web.py

2012-02-21 21:01 501 查看
Nginx是俄罗斯人Igor Sysoev 编写的一款高性能的HTTP和反向代理服务器。其采用epoll 的机制,官方宣传可支持50000个并发。

下面介绍nginx 作为反向代理负载均衡服务器和HTTP服务器的配置用法。

下图为nginx 作为反向代理均衡服务器,和HTTP 代理服务器的简单配置用法。

upstream frontends 中列出所有服务器地址,nginx 自动均衡分发请求到各个服务器。
http {
# Enumerate all the Tornado servers here
upstream frontends {
ip_hash;
server 192.168.0.1:8888;
server 192.168.0.2:8889;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://frontends; }
}

server {
listen 8000;
server_name Cache;
error_log logs/test.log;

location / {
uwsgi_pass 127.0.0.1:9001;
include uwsgi_params;
}
}
}

第二个server 作为http 服务器,服务于uwsgi + web.py
web.py 简单demo,文件名test.py.

import web
import time
import socket
urls = (
'/', 'index'
)

class index:
def GET(self):
strtime1 =str(time.time())
strtime2 =str(time.time())
return strtime1+"Hello, world!"+strtime2

app = web.application(urls, globals())
application = app.wsgifunc()用uwsgi -s 127.0.0.1:9001 -w test 
在启动nginx ,访问l27.0.0.1:8000就看到效果了。

值得一说的是在启动uwsgi时,大家可能会遇到这样的问题

unable to load app 0 (mountpoint='') (callable not found or import error)

这是因为大家被这句话写错了application=app.wsgifunc(),uwsgi 找不到入口地址application = app.wsgifunc()
application = app.wsgifunc()


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息