[转]nginx 配置flask

1、安装flup
easy_install flup
mkdir -p /home/eric/workspace/python_app/flask_test/
vim /home/eric/workspace/python_app/flask_test/app.py
2、编辑APP
#!/usr/bin/env python
# encoding: utf-8
 
from flask import Flask
app = Flask(__name__)
 
@app.route("/")
def hello():
        return "Hello Flask World!"
3、编辑FCGI
#!/usr/bin/env python
# encoding: utf-8
 
from app import app
from flup.server.fcgi import WSGIServer
 
WSGIServer(app,bindAddress='/tmp/flask_test_app.sock').run()

pcre,正则表达式相关的类库,ospenssh,安装nginx需要
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz
        tar zxvf pcre-8.12.tar.gz
        cd pcre-8.02
        ./configure
        make
        make install
        cd ..

4、安装nginx
root@eric-desktop:/usr/local/src# wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz
root@eric-desktop:/usr/local/src# tar zxvf nginx-0.8.46.tar.gz
root@eric-desktop:/usr/local/src# cd nginx-0.8.46
root@eric-desktop:/usr/local/src/nginx-0.8.46# ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.12 --add-module=/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/nginx/
root@eric-desktop:/usr/local/src/nginx-0.8.46# make
root@eric-desktop:/usr/local/src/nginx-0.8.46# make install
root@eric-desktop:/usr/local/src/nginx-0.8.46# nginx
[alert]: Phusion Passenger is disabled because the 'passenger_root' option is not set. Please set this option if you want to enable Phusion Passenger.
# 打开浏览器看看
root@eric-desktop:/usr/local/src/nginx-0.8.46# firefox http://localhost
# 会看到“Welcome to nginx!”,就表示启动成功了,好吧, 配置一下passenger
5、编辑nginx配置
root@eric-desktop:/usr/local/src/spawn-fcgi# vim /usr/local/nginx/conf/vhosts/python.lvh.me
server{
         listen 80;
         server_name python.lvh.me;
         location / {
             include fastcgi_params;
             fastcgi_param SCRIPT_FILENAME "";
             fastcgi_param PATH_INFO $fastcgi_script_name;
             fastcgi_pass unix:/tmp/flask_test_app.sock;
                 }
 
         }
root@eric-desktop:/usr/local/src/spawn-fcgi# python /home/eric/workspace/python_app/flask_test/fcgi.py method=prefork/threaded minspare=50 maxspare=50 maxchildren=1000 &
root@eric-desktop:/usr/local/src/spawn-fcgi# chmod 777 /tmp/flask_test_app.sock
root@eric-desktop:/usr/local/src/nginx-0.8.46# killall -9 nginx
root@eric-desktop:/usr/local/src/nginx-0.8.46# nginx
root@eric-desktop:/usr/local/src/nginx-0.8.46# firefox http://python.lvh.me
# 看到"Hello Flask World!"就对了

转自:http://www.douban.com/note/136553861/

相关推荐