1. Download the required package
wget http://nginx.org/download/nginx-1.5.9.tar.gz
wget http://projects.unbit.it/downloads/uwsgi-2.0.4.tar.gz
wget http://exim.mirror.fr/pcre/pcre-8.34.tar.gz
2. Compile and install
#安装pcre, the Nginx HTTP rewrite module uses the
Tar zxvf pcre-8.34.tar.gz
CD pcre-8.34/
./configure
sudo make
sudo make install
Cd..
#安装nginx------------------------------------------
TAR-ZXVF nginx-1.5.9.tar.gz
CD nginx-1.5.9
./configure--user=nobody--group=nobody--prefix=/usr/local/nginx--with-http_stub_status_module--with-cc-opt= '- O3 '--with-cpu-opt=opteron
sudo make && sudo make install
Cd..
#安装uwsgi-------------------------------------------
TAR-ZXVF uwsgi-2.0.4.tar.gz
CD uwsgi-2.0.4
sudo make
vi/etc/ld.so.conf #添加动态链接库目录/usr/local/lib
#添加行:/usr/local/lib
Ldconfig #使之生效
CP Uwsgi/usr/bin
Cd..
#--------------------------------------------------
#Flask, there are many ways to install: Yum, Apt-get, Pip
sudo pip install flask
3. Edit Nginx and Uwigi configuration files
nginx.conf Configuration
$ cat/usr/local/nginx/conf/nginx.conf
User nobody;
Worker_processes 2;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
#log_format Main ' $remote _addr-$remote _user [$time _local] "$request"
# ' $status $body _bytes_sent ' $http _referer '
# ' $http _user_agent ', ' $http _x_forwarded_for ';
#access_log Logs/access.log Main;
Sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
Keepalive_timeout 65;
gzip on;
server {
Listen 80;
server_name #记得做下本地hosts
Location/{
Uwsgi_pass 127.0.0.1:9000;
Include Uwsgi_params;
Uwsgi_param Uwsgi_chdir/data/www.111cn.net/flask/yw; #网站目录可以选, because Uwsgi is still to be configured.
Uwsgi_param Uwsgi_script Run; Run the file #run就是flask/yw directory run.py
Access_log off;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
#location ~ php$ {
# root HTML;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param Script_filename/scripts$fastcgi_script_name;
# include Fastcgi_params;
#}
}
}
Uwsgi.ini Configuration
Method 1:
$ cat/usr/local/nginx/conf/uwsgi_ini
[Uwsgi]
Socket = 0.0.0.0:9000
Master = True
Pidfile =/usr/local/nginx/uwsgi.pid
processes = 8
Workers = 2
ChDir =/data/www.111cn.net/flask/yw #网站目录
callable = App,you know! in the app #这个就是run. py
Pythonpath =/data/www.111cn.net/flask
Profiler=true
Memory-report=true
Enable-threads = True
Logdate=true
limit-as=6048
Daemonize=/data/logs/flask.log #run. The information generated after the run of Py is recorded in the Flask.log log file
Method 2:
[Uwsgi]
Socket = 0.0.0.0:9000
Pidfile =/usr/local/nginx/uwsgi.pid
processes = 8
Master = True
ChDir =/data/www.111cn.net/flask/yw #网站目录
#module = run #这个就是run. py
callable = App,you know! in the app #这个就是run. py
Pythonpath =/data/www.111cn.net/flask
4. Run and stop Uwsgi and Nginx
Sudo/usr/bin/uwsgi--ini/usr/local/nginx/conf/uwsgi.ini
sudo sudo/usr/local/nginx/sbin/nginx
#kill
sudo killall nginx
sudo killall-9 Uwsgi