I'm using tornado to build a web server. Now everything's ready, I can visit my website with the IP address of my server.
Also, I've got a domain name but I don't know how to use the domain name to visit my server.
For example, the IP is a.a.a.a
and the domain name is www.mysite.com
. For now I can use www.mysite.com
to visit my website but only the index page. Meaning that I can't visit all of sub pages, such as www.mysite.com/page1.html
.
Here is my code:
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)
I think I should do some configuration for the tornado but I don't know how.
I've found the solution.
In fact it is because I use IP address in the backend code and the frontend code.
So there exists a cross-domain problem.
I replace all of IP with the domain name and it works. Here is an example:
backend:
replace self.write("http://a.a.a.a/something.html")
with self.write("http://www.example.com/something.html")
frontend(ajax):
replace url:'http://a.a.a.a' + '/index?key=' + request,
with url:'http://www.example.com' + '/index?key=' + request,