web(一)----tornado nginx配置
参考 http://www.luokr.com/p/2
上一节安装了tornado, 本节安装ngix, Nginx来将web请求代理到Tornado web server
一. 首先安装Nginx.
- $ rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
- $ yum install nginx
二. 接下来是Nginx的配置.
- 新建配置文件$ vim /etc/nginx/conf.d/tornado.conf (默认配置文件是/etc/nginx/sites-available/default)
- 输入如下内容:
upstream tornado { server 127.0.0.1:8888; } server { listen 80; root /var/www; index index.py index.html; server_name server; location / {
root /var/www; if (!-e $request_filename) { rewrite ^/(.*)$ /index.py/$1 last; } } location ~ /index\.py { 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.
$ service nginx restart
四. 通过http://localhost访问.
注意:
(1)其中的root /var/www是index.py所在的文件夹.
(2)http://localhost 访问
(3)如果访问http://localhost/template 则index.py中为(r"/index.py/template", TemplateHandler)