先说说思路html
1、安装这些东西,tornado, supervisor( sudo pip install supervisor 在linux 系统上), 安装 nginx (sudo apt-get install nginx -y) linux
2、让supervior 和 已经写好的tornado 服务挂钩 nginx
用supervisor 来管理服务和进程服务器
在命令行里面使用。tornado
而后,再在 supervisord.conf 最后面添加这几行this
这里tornado center.py 的本地服务地址是8100,写在center.py 文件里面了。spa
固然为了标准,咱们能够添加这几行在这里面,用来产看进程id,还有进程log(unix标准要执行)命令行
而后,步骤是3d
1)unix
$ sudo supervisord
2)
$ sudo supervisorctl start all
(当上述命令执行完毕后,系统会自动执行上面所添加的program:segm_cn)
3、咱们来配置nginx
当咱们安装完nginx后,咱们能够经过
$ sudo service nginx start
来启动。
然后,咱们须要增长一个新的服务,这里好比说是
tornado
在 /etc/nginx/sites-availble 下新建一个tornado.conf 其内容看似:
# this is the real tornado service upstream tornado { server 127.0.0.1:8100; # tornado 服务的本地地址,上面说过了是8100端口 } server { listen 80; # 监听互联网上的80 端口,而后转交给本地的 torando 即8100端口 root /home/software/segm_cn; # tornado 服务文件所在目录 index center.py index.html; #index index.py index.html; server_name server; location / { if (!-e $request_filename) { rewrite ^/(.*)$ /center.py/$1 last; } } #location ~ /center\.py { location ~ / { # 将全部请求,都转交给upstream使用 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; # 这里是指向上面的upstream } }
而后,
再
$ sudo ln -s /etc/nginx/sites-available/tornado.conf /etc/nginx/sites-enabled/tornado.conf $ sudo service nginx reload $ sudo service nginx restart
这时候,全部对服务器ip80端口的访问,所有都定向到本地服务的8100端口了。
咱们还能够查看一下supervisor的log服务,来查看究竟是谁访问的,访问的一个什么程度。
好了。很爽!!!
咱们分几个简单的步骤