Running Tornado in apache

旧街凉风 提交于 2019-12-06 11:24:51

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

The WSGIApplication handlers are relative to the webserver root. If your application url is /myapp, your 'application' must look like this:

application = tornado.wsgi.WSGIApplication([
    (r"/myapp", MainHandler),
    (r"/myapp/login/etc", LoginEtcHandler),
])

Oh, and it seems like the documentation is shit (as usual) and __name__ will look something like this when running under apache: _mod_wsgi_8a447ce1677c71c08069303864e1283e.


So! a correct "Hello World" python script will look like this:

/var/www/wsgi-scripts/myapp.wsgi:

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

class MainHandler(tornado.web.RequestHandler):
    def get(self):
         self.write('Hello World')

application = tornado.wsgi.WSGIApplication([
    (r"/myapp", MainHandler),
])

And in the apache config (not .htaccess):

WSGIScriptAlias /myapp /var/www/wsgi-scripts/myapp.wsgi

To use tornado in apache,add a mod-wsgi plugin to apache.

apt-get install libapache2-mod-wsgi

Write a tornado wsgi server with .wsgi NOTE:Dont use__name__

Configure the apache.conf to run your server.To configure use this mod-wsgi guide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!