1.下載所需要的軟件包
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.編譯安裝
#安裝pcre ,Nginx的HTTP Rewrite模塊會用到
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,安裝方式很多:yum、apt-get、pip
sudo pip install flask
3.編輯nginx和uwigi配置文件,直接拿了大牛的配置稍微修改了下: nginx.conf
kkk@bogon:~$ 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/flask/yw; #網站目錄可以選,因為uwsgi那還是要配置的
uwsgi_param UWSGI_SCRIPT run; #run就是flask/yw目錄下運行文件run.py
access_log off;
}
error_page 500 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
kkk@bogon:~$ 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/flask/yw #網站目錄
callable = app #這個就是run.py裡的app,you know!
pythonpath = /data/www/flask
profiler=true
memory-report=true
enable-threads = true
logdate=true
limit-as=6048
daemonize=/data/logs/flask.log #run.py運行後產生的信息都記錄在這的flask.log日志文件裡
#配置2
[uwsgi]
socket = 0.0.0.0:9000
pidfile = /usr/local/nginx/uwsgi.pid
processes = 8
master = true
chdir = /data/www/flask/yw #網站目錄
#module = run #這個就是run.py
callable = app #這個就是run.py裡的app,you know!
pythonpath = /data/www/flask
4.運行uwsgi和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
原文:http://my.oschina.net/jk409/blog/366084