本文介绍了在Apache中运行龙卷风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最终目标是使用python实现WebSocket服务器.

My end goal is to implement a WebSocket server using python.

我通过在我的python脚本中导入 tornado 来实现此目的.我还在Apache中安装了mod_wsgi,并且其脚本输出Hello World !,因此WSGI似乎运作良好.据我所知,龙卷风也运转良好.

I'm accomplishing this by importing tornado in my python scripts. I've also installed mod_wsgi in apache, and their script outputs Hello World!, so WSGI seems to be working fine. Tornado is also working fine as far as I can tell.

当我使用 tornado的wsgi你好,世界"脚本时,问题就来了:

The issue comes when I use tornado's wsgi "Hello, world" script:

import tornado.web
import tornado.wsgi
import wsgiref.simple_server

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

if __name__ == "__main__":
    application = tornado.wsgi.WSGIApplication([
        (r"/", MainHandler),
    ])
    server = wsgiref.simple_server.make_server('', 8888, application)
    server.serve_forever()

首先,出现500错误,日志告诉我WSGI找不到应用程序".

First, I get a 500 error and the log tells me WSGI can't find 'application'.

所以我删除了if __name__ == "__main__",并且页面无限加载.

So I remove if __name__ == "__main__", and the page loads infinitely.

我认为这是由于server.serve_forever()造成的,因此我尝试将其删除以查看世界您好

I assume this is because of server.serve_forever() so I removed it in an attempt to see Hello, world

但是现在我只得到404: Not Found.这不是我的apache 404页面,我知道服务器可以找到我的主要.wsgi文件...

But now I just get 404: Not Found. It's not my apache 404 page, and I know that the server can find my main .wsgi file...

推荐答案

您不能将Websocket与Tornado的WSGIApplication一起使用.要使用Tornado的websocket支持,您必须使用Tornado的HTTPServer,而不是apache.

You can't use websockets with Tornado's WSGIApplication. To use Tornado's websocket support you have to use Tornado's HTTPServer, not apache.

这篇关于在Apache中运行龙卷风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:16