tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控
2014-02-10 16:04
316 查看
tornado zbar 二维码识别 ,配合nginx 反向代理,supervisord 监控
1、zbar识别二维码程序,python2.6.6
2、下面给出我的supervisord的配置。请各位看官根据自己的实际情况修改对应的root用户。
3、最后第三个配置文件是nginx的反向代理配置。
1、zbar识别二维码程序,python2.6.6
#!/usr/bin/env python # coding: u8 import os import zbar import Image import urllib import uuid import requests import sys import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web import requests import sys import re from tornado.options import define, options define("port", default=9000, help="run on the given port", type=int) def qrRead(url): proxies = {"http": "http://weibh:loveme@134.44.36.120:2012/",} uuid1 = uuid.uuid1() filename=str(uuid1)+".jpg" #print uuid1 #urllib.urlretrieve(url, filename) r=requests.get(url,proxies=proxies,stream=True) with open(filename, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() f.close() # create a reader scanner = zbar.ImageScanner() # configure the reader scanner.parse_config('enable') # obtain image data pil = Image.open(filename).convert('L') width, height = pil.size #pil.show() raw = pil.tostring() # wrap image data image = zbar.Image(width, height, 'Y800', raw) # scan the image for barcodes scanner.scan(image) tmpdata='' # extract results for symbol in image: # do something useful with results print symbol.type, '图片内容为:\n%s' % symbol.data tmpdata=tmpdata+symbol.data # clean up del(image) os.remove(filename) return tmpdata class MainHandler(tornado.web.RequestHandler): def get(self): #self.write('hello'+sys.argv[1]) self.set_header("Content-Type", "text/plain") #url = 'http://www.prepolino.ch/sprache/trennen/bilder/test.gif' #qrRead(url) url=self.get_argument("url") self.write(qrRead(url)) def post(self): self.set_header("Content-Type", "text/plain") #url = 'http://www.prepolino.ch/sprache/trennen/bilder/test.gif' #qrRead(url) url=self.get_argument("url") self.write(qrRead(url)) def main(port): tornado.options.parse_command_line() application = tornado.web.Application([ (r"/", MainHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(port) tornado.ioloop.IOLoop.instance().start() if __name__ == '__main__': port=int(sys.argv[1]) main(port)
2、下面给出我的supervisord的配置。请各位看官根据自己的实际情况修改对应的root用户。
;/etc/supervisord.conf [unix_http_server] file = /var/run/supervisor.sock chmod = 0777 chown= root:dabao [inet_http_server] # Web管理界面设定 port=127.0.0.1:9001 username = dabao password = dabao [supervisorctl] ; 必须和'unix_http_server'里面的设定匹配 serverurl = unix:///var/run/supervisord.sock [supervisord] logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=true ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) user=root ; (default is current user, required if root) childlogdir=/var/log/ ; ('AUTO' child log dir, default $TEMP) [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [program:groupworker] command=python3 /home/dabao/8887.py 88%(process_num)02d process_name=%(program_name)s_%(process_num)02d numprocs=3 numprocs_start=1 autostart = true startsecs = 5 redirect_stderr = true stdout_logfile_maxbytes = 20MB stdoiut_logfile_backups = 20 stdout_logfile = /var/log/groupworker.log
3、最后第三个配置文件是nginx的反向代理配置。
nginx 1.4.4 /etc/nginx/conf.d/tornado.conf upstream tornado { server 127.0.0.1:8887; server 127.0.0.1:8888; server 127.0.0.1:8889; } server { listen 8090; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://tornado; } }
相关文章推荐
- Nginx 反向代理配合Tomcat部署web项目
- nginx设置反向代理后无法识别css,js等等
- centos 6.5 下使用nginx 反向代理 多个tornado
- lvs + keepalived + nginx + tomcat高可用负载反向代理服务器配置(三) Nginx
- nginx反向代理服务器端口问题
- Nginx应用场景(二)反向代理,负载均衡
- 解决nginx使用proxy_pass反向代理时,cookie丢失的问题
- Nginx 使用反向代理时Hessian 的 411 错误解决方案
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
- Nginx 反向代理 Tomcat 传递自定义 Head 问题总结
- nginx 反向代理apache服务器 配置java与PHP共存环境
- Nginx实战之反向代理WebSocket的配置实例
- Nginx配置文件(反向代理服务器)
- Nginx多Server反向代理配置
- Nginx反向代理、CORS、JSONP等跨域请求解决方法总结
- nginx反向代理原理简介
- nginx反向代理java web应用,网页链接的问题
- nginx 反向代理,负载均衡,重定向,读写分离
- nginx反向代理后获取不到客户端的真实ip地址
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解