公司新的项目,以Nginx做web服务器,Flask作为web框架,Flup接受请求并调用应用程序,Python作为开发语言,MySQL作为数据库存储。现在将开发过程做记录,方便以后参考。
版本
Nginx:1.12.1
Flask:0.12.2
Flup:1.0.2
Python:2.7.10
MySQLdb:1.2.4b4
mysql-server:5.7.19
部署
安装brew
$ ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装openssl
$ brew install openssl
安装mysql
$ brew install mysql
$ mysql.server start
添加MySQLdb模块
$ pip uninstall mysql-python
$ brew uninstall mysql-connector-c
$ tar zvxf MySQL-python-1.2.4b4.tar
$ cd MySQL-python-1.2.4b4
$ vim site.cfg
# The path to mysql_config.
# Only use this if mysql_config is not on >your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/bin/mysql_config
$ sudo python setup.py install
安装Flask
$ sudo pip install flask
$ pip list
安装Nginx
$ brew install nginx
$ nginx
安装Flup
$ pip install flup
配置
配置Nginx
$ ln -s /usr/local/etc/nginx/nginx.conf /nginx/nginx.conf
$ sudo vim /nginx/nginx.conf
http {
server {
listen 80;
server_name localhost;
location / {
try_files $uri @flaskr;
}
location @flaskr {
include fastcgi_params;
fastcgi_param SCRIPT_NAME "";
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_pass unix:/tmp/flaskr-fcgi.sock;
}
}
}
$ sudo nginx -t
$ nginx -s reload
添加fcgi文件
$ vim /~/flaskr.fcgi
#!/usr/bin/python
from flup.server.fcgi import WSGIServerfrom app import app
if __name__ == '__main__':
WSGIServer(app, bindAddress='/tmp/flaskr-fcgi.sock').run()
$ sudo chmod +x /~/flaskr.fcgi
$ sudo python /~/flaskr.fcgi &
添加sock文件权限
$ sudo chmod 777 /tmp/flaskr-fcgi.sock