采用离线安装方式, ubuntu开发环境(centos等环境类似)
安装
$ wget http://nginx.org/download/nginx-1.6.0.tar.gz #仅784k
$ cd nginx-1.6.0.tar.gz
$ tar -zxvf nginx-1.6.0.tar.gz
$ ./configure
$ make
$ sudo make install
常用命令
启动: sudo /usr/local/nginx/sbin/nginx [-c nginx.conf]
重启: sudo /usr/local/nginx/sbin/nginx -s reload
关闭: sudo /usr/local/nginx/sbin/nginx -s quit
验证安装启动成功
curl localhost
显示welcome的话就OK了
常见问题
sudo netstat -tulpn | grep 80
sudo kill -s (PID)
安装
wget http://projects.unbit.it/downloads/uwsgi-2.0.5.1.tar.gz #752k
sudo python setup.py install
验证成功
/usr/bin/uwsgi -h
出现帮助提示就行了.
安装
wget https://pypi.python.org/packages/source/F/Flask/Flask-0.10.1.tar.gz
sudo python setup.py install
验证成功
flask.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
python flask.py
, 访问curl 127.0.0.1:5000
成功即可
sudo apt-get install mysql-server
, 使用mysql -u root -p
保证登陆成功即可.
python mysql组件: sudo apt-get install python-mysqldb
nginx本身只能调用静态文件, 它需要依赖网关协议文件来调用脚本. uwsgi是nginx的标准模块, 用于调用其它脚本.
修改nginx的配置文件conf/nginx.conf
以指向uwsgi
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;
root html;
index index.html index.htm;
}
修改uwsgi文件, 配置脚本文件app_config.xml
, 即运行的文件名以及应用名(nginx, uwsgi和app间需要通过socket进行交互)
<uwsgi>
<pythonpath>/home/chenjiebin/web/flaskdemo</pythonpath>
<module>flask</module>
<callable>app</callable>
<socket>127.0.0.1:5000</socket>
<master/>
<processes>4</processes>
<memory-report/>
</uwsgi>
sudo /usr/local/nginx/sbin/nginx
将默认调用conf/nginx.conf
文件
前台程序 sudo /usr/local/bin/uwsgi -x $(WD)/app_config.xml
deamon程序: sudo /usr/local/bin/uwsgi -x $(WD)/app_config.xml -d /var/log/uwsgi/uwsgi.log
nginx -s reload
会重载配置文件ps aux | grep uwsgi
; sudo kill -s HUP $(PID)
1. Centos 6.4下nginx+uwsgi+flask的运行环境搭建
Ubuntu下nginx+uwsgi+flask的运行环境搭建,布布扣,bubuko.com
Ubuntu下nginx+uwsgi+flask的运行环境搭建
原文地址:http://blog.csdn.net/qingfengmanbu/article/details/38390497