【问题标题】:How to set the domain name for tornado如何设置龙卷风的域名
【发布时间】:2017-05-13 05:53:16
【问题描述】:

我正在使用 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)

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

【问题讨论】:

    标签: python web server tornado


    【解决方案1】:

    我找到了解决方案。

    其实是因为我在后端代码和前端代码中都使用了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,

    【讨论】:

      猜你喜欢
      • 2017-10-08
      • 2017-08-02
      • 2017-06-16
      • 2011-07-24
      • 2018-12-17
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多