如何设置龙卷风的域名

时间:2017-05-13 05:53:17

标签: python web server tornado

我正在使用龙卷风来构建一个Web服务器。现在一切准备就绪,我可以使用我服务器的IP地址访问我的网站。

另外,我有一个域名,但我不知道如何使用域名访问我的服务器。

例如,IP为a.a.a.a,域名为www.mysite.com。现在我可以使用www.mysite.com访问我的网站,但只能访问索引页面。这意味着我无法访问所有子页面,例如www.mysite.com/page1.html

这是我的代码:

class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/(.*js$)", tornado.web.StaticFileHandler, {'path': 'static/'}),
            (r"/(.*css$)", tornado.web.StaticFileHandler, {'path': 'static/'}),
            (r"/(.*xml$)", tornado.web.StaticFileHandler, {'path': 'static/'}),
            (r"/(.*jpg$)", tornado.web.StaticFileHandler, {'path': 'static/'}),
            (r"/(.*png$)", tornado.web.StaticFileHandler, {'path': 'static/'}),
            (r"/(.*ico$)", tornado.web.StaticFileHandler, {'path': 'static/'}),

            (r"/(.*country\.html$)", PageHandler),
            (r"/(.*city\.html$)", PageHandler),
            (r"/(.*look\.html$)", PageHandler),

            (r"/(index)", SearchHandler),
            (r"/$", IndexHandler),
        ]
        settings = dict(
            #template_path = os.path.join(os.path.dirname(__file__), "beejeen/"),
            #static_path = os.path.join(os.path.dirname(__file__), "beejeen/"),
        )
        super(Application, self).__init__(handlers, **settings)

我想我应该为龙卷风做一些配置,但我不知道如何。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

实际上是因为我在后端代码和前端代码中使用了IP地址。

因此存在跨域问题。

我用域名替换所有IP并且它有效。这是一个例子:
后端:
self.write("http://a.a.a.a/something.html")替换为self.write("http://www.example.com/something.html")

前端(AJAX):
url:'http://a.a.a.a' + '/index?key=' + request,替换为url:'http://www.example.com' + '/index?key=' + request,

相关问题