本来打算使用nginx+uwsgi但是在使用过程中要么是socketio不停的重连(每次都打开新的端口),要么就直接无法使用。(还没有找到原因)
所以尝试使用nginx+gunicorn的方式, 结果socketio工作的还不错.以下是一个简单配置实例。
首先配置Nginx
nginx.conf:
worker_processes 1;
error_log logs/error.log debug;
pid logs/nginx.pid;
events {
use epoll;
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;
gzip on;
upstream BACKEND {
server unix:/tmp/gunicorn.sock;
}
server {
listen 80;
location ^~/static/{
root /usr/local/peach3/peach2Produce/;
}
location / {
charset utf-8;
proxy_pass http://BACKEND;
}
}
}
主要是使用的socket来和gunicorn通信的
配置Gunicorn
下面是启动gunicorn时的配置文件(*.conf)
workers = 1
bind = 'unix:/tmp/gunicorn.sock'
worker_class='eventlet'
accesslog='-'
worker_connections = 100
注意一下 我使用的是eventlet。gunicorn如果使用gevent,不知道为什么,python在使用gunicorn运行的时候会出现greenlet的异常.
好了最基本的配置完成了。
然后启动nginx,启动gunicorn
我用手机记了一下时,大概在25s或者是30s会重新连接一下socketio。但是并不影响使用。