[转]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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值