标签:stat requests events daemon src pos yum world ret
先安装以下的软件(如果有的话,就可以不安装了,例如使用rpm -qa zlib-devel先查看下)
yum install zlib-devel -y
yum install openssl-devel -y
tar -zxvf解压
./configure --prefix=/usr/local/python #安装到/usr/local/python目录下。
make
make install
先安装pcre-devel:
yum install pcre-devel -y
./configure --prefix=/usr/local/nginx
make && make install
cat /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
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"‘;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
access_log /usr/local/nginx/logs/flask_access.log main;
error_log /usr/local/nginx/logs/flask_error.log error;
client_max_body_size 200M;
location / {
include uwsgi_params;
uwsgi_pass unix:/dev/shm/uwsgi.sock;
index index.html index.htm;
}
}
}
启动nginx:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx
注意:uwsgi_pass unix:/dev/shm/uwsgi.sock;需要和uwsgi的配置相对应!
[uwsgi]
uid = root
gid = root
socket = /dev/shm/uwsgi.sock
chmod-socket = 666
enable-threads = true
master = true
plugins = /usr/local/python/bin/python
vhost = true
workers = 5
max-requests = 1000
pidfile = /var/run/uwsgi.pid
daemonize = /var/log/uwsgi.log
chdir = /root/ops_dev/
module = ops_dev
callable = app
启动uwsgi,有些报错没什么事:
/usr/local/python/bin/uwsgi /root/uwsgi.ini
cat /root/ops_dev/ops_dev.py
# -*- coding: UTF-8 -*-
from flask import Flask
app = Flask(__name__)
@app.route(‘/‘, methods=[‘GET‘, ‘POST‘])
def index():
return ‘Hello world,Python ops_dev!‘
编写完需要重启uwsgi,开改动代码都需要重启uwsgi,直接使用pkill进行重启即可:
pkill uwsgi
访问http://localhost:8080/进行测试。
访问日志记录(nginx和uwsgi的访问日志,可用来排错。):
标签:stat requests events daemon src pos yum world ret
原文地址:http://www.cnblogs.com/nulige/p/7604589.html