uWSGI旨在为部署分布式集群的网络应用开发一套完整的解决方案。主要面向web及其标准服务。由于其可扩展性,能够被无限制的扩展用来支持更多平台和语言。uWSGI是一个web服务器,实现了WSGI协议,uwsgi协议,http协议等。
uWSGI的主要特点是:
uWSGI服务器自己实现了基于uwsgi协议的server部分,我们只需要在uwsgi的配置文件中指定application的地址,uWSGI就能直接和应用框架中的WSGI application通信
pip install uwsgi
这里给个样例作为参考
[uwsgi]
# 指向项目目录
chdir = /XXX/XXX/XXXX
# 外部访问地址,主要是指定端口号。可以指定多种协议:http 或 socket
socket = 127.0.0.1:8888
# http = 127.0.0.1:8888
# flask启动程序文件
wsgi-file = XXX.py
# flask在manage.py文件中的app名
callable = app
# 处理器数
processes = 4
# 存储日志信息
logto = /XXX/XXX/XXX.log
# 线程数
threads = 8
# 设置uwsgi的pid文件
pidfile = /XXX/XXX.pid
# 设置uwsgi的status文件
statusfile = /XXX/XXX.status
这里给个样例作为参考
# the upstream component nginx needs to connect to
upstream XXX {
server 127.0.0.1:7777;
}
# configuration of the server
server {
# the port your site will be served on
listen 1002;
# the domain name it will serve for
#server_name .example.com; # substitute your machine's IP address or FQDN
server_name XXXX;
charset utf-8;
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass XXX;
include uwsgi_params;
# the uwsgi_params file you installed
}
}
PS. 对于新建的配置文件,需要在nginx.conf里面加入引入路径:include vhosts/*.conf
user work;
worker_processes auto;
#error_log logs/error.log;
error_log /data/logs/nginx/host/logs/host_error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
accept_mutex off;
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"';
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent $request_body "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
access_log /data/logs/nginx/host/logs/host_access.log main;
server_tokens off;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
client_header_buffer_size 4k;
client_max_body_size 20M;
open_file_cache max=102400 inactive=30s;
open_file_cache_valid 30s;
open_file_cache_min_uses 0;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript application/json;
include vhosts/*.conf;
}
uwsgi --ini uwsgi.ini
cat uwsgi/uwsgi.pid
ps aux | grep uwsgi
uwsgi --reload uwsgi/uwsgi.pid
uwsgi --stop uwsgi/uwsgi.pid
uwsgi --version
nginx -t
nginx -s reload
nginx -t
nginx -s stop