【问题标题】:setting up gevent-socket using flask,nginx and gunicorn使用烧瓶、nginx 和 gunicorn 设置 gevent-socket
【发布时间】:2015-03-26 19:29:29
【问题描述】:

以下是我的python代码

from gevent import monkey;monkey.patch_all()
from flask import Flask,render_template, url_for, request, redirect, flash,jsonify,session,Markup
from socketio import socketio_manage
from socketio.namespace import BaseNamespace
from socketio.server import SocketIOServer

app=Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'

class ChatNamespace(BaseNamespace):
  def recv_connect(self):
    print "successfully connected"
    self.emit('show_result','successfully connect')
  def on_receive_message(self,msg):
    print "message is "+msg["data"]
    self.emit('show_result2',msg["data"])
@app.route('/')
def index():
   #print "in the function"
   return render_template('index.html')

@app.route("/socket.io/<path:path>")
 def run_socketio(path):
  socketio_manage(request.environ, {'/test': ChatNamespace})
  return 'ok'

if __name__=='__main__':
  #app.run(debug=True, port=80, host='0.0.0.0')
   app.debug=True
   #app.run()
   SocketIOServer(('0.0.0.0', 5000), app,resource="socket.io").serve_forever()
print "successfull listen to socket"

以下是nginx配置 服务器{

location / {
  proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;
  try_files $uri @proxy;
}
location @proxy {
    proxy_pass http://127.0.0.1:8000;
}
location /templates {
    alias  /home/www/flask_project/templates/;
}
 location /script {
    alias  /home/www/flask_project/script/;
  }
  location /static {
    alias  /home/www/flask_project/static/;
  }

 }

每次运行应用程序时,我都会使用以下命令
gunicorn main2:app -b localhost:5000

我知道我缺少很多信息来在实时服务器上运行这个 gevent-socketio 应用程序。 谁能帮帮我,我对这种网络套接字技术完全陌生

【问题讨论】:

    标签: python-2.7 nginx gunicorn gevent-socketio


    【解决方案1】:

    你试过FlaskSocketio吗??

    如果您尝试在没有扩展的情况下执行此操作,您将需要 socketio gunicorn worker 来运行您的应用程序。

    gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker module:app
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-19
      • 2012-12-27
      • 1970-01-01
      • 2021-05-17
      • 2022-11-12
      • 2017-05-11
      • 2016-08-30
      • 2017-06-06
      相关资源
      最近更新 更多