uWSGI安装
yum install -y gcc python-devel
pip install uWSGI
uWSGI启动
命令行启动
uwsgi --socket 127.0.0.1:5001 \
--wsgi-file srv_m/srv_a.py \
--callable app \
--processes 4 --threads 2 \
--stats 127.0.0.1:9191 \
--buffer-size 32768 \
--logto ../xx.log
# --wsgi-file:python 启动文件
# --callable:python 文件中的全局应用变量
配置文件启动
cat >> srv_a.ini << EOF
[uwsgi]
# 项目路径
chdir = /root/srv_m/
# python 文件路径
wsgi-file = /root/srv_m/srv_a.py
# socket file's location
socket = /tmp/srv_m.sock
pidfile = /tmp/srv_m.pid
# permissions for the socket file
chmod-socket = 666
# 启动用户,注意,uid要用root,gid要用nginx,除非nginx用root用户
uid = root
gid = nginx
#the variable that holds a flask application inside the module imported at line #6
callable = app
#location of log files
logto = /root/srv_m/srv_m.log
EOF
uwsgi --ini srv_a.ini
Nginx配置
#location配置
#以下为2种方式,一种是unix sock,另外一种为tcp
upstream hello-test {
server unix:///tmp/srv_m.sock;
#server 127.0.0.1:5001;
}
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
uwsgi_pass hello-test;
#非常重要,不要忘记
include uwsgi_params;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
}
网友评论