配置nginx后看不到index页面
After configure the nginx, I can't see the index page
这是我第一次使用nginx
我写了一个简单的python/tornado代码如下,当我使用python server.py
时,我可以看到index.html页面。
from tornado.options import define, options
from db import MongoImpl
define("port", default=8000, help="run on the given port", type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render("./pages/index.html")
app = tornado.web.Application([(r'/', IndexHandler)],
debug=True)
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
然后我开始配置 nginx.conf,我在默认 nginx.conf 中添加了以下内容:
http {
server{
listen 8000;
root /home/ubuntu/work/mytornado/pages;
index index.html index.htm;
}
然后我nginx -s reload
然而,当我使用 http://myipaddress
时,我只看到 nginx 欢迎页面,而不是我的索引 html...
有什么问题吗?
你不能 运行 端口 8000 上的 nginx 和你的 tornado 服务器。你需要给它们每个不同的端口,并使用 proxy_pass
指令配置 nginx 代理到 tornado(这将替换这里的 root
指令,它为文件系统中的页面提供服务。如果你想让 nginx 为文件系统中的一些文件和 tornado 中的一些文件提供服务,那么你需要使用两个 location
块)。
可以在文档中找到用于 tornado 的完整 nginx 配置:http://www.tornadoweb.org/en/stable/guide/running.html#running-behind-a-load-balancer
这是我第一次使用nginx
我写了一个简单的python/tornado代码如下,当我使用python server.py
时,我可以看到index.html页面。
from tornado.options import define, options
from db import MongoImpl
define("port", default=8000, help="run on the given port", type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render("./pages/index.html")
app = tornado.web.Application([(r'/', IndexHandler)],
debug=True)
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
然后我开始配置 nginx.conf,我在默认 nginx.conf 中添加了以下内容:
http {
server{
listen 8000;
root /home/ubuntu/work/mytornado/pages;
index index.html index.htm;
}
然后我nginx -s reload
然而,当我使用 http://myipaddress
时,我只看到 nginx 欢迎页面,而不是我的索引 html...
有什么问题吗?
你不能 运行 端口 8000 上的 nginx 和你的 tornado 服务器。你需要给它们每个不同的端口,并使用 proxy_pass
指令配置 nginx 代理到 tornado(这将替换这里的 root
指令,它为文件系统中的页面提供服务。如果你想让 nginx 为文件系统中的一些文件和 tornado 中的一些文件提供服务,那么你需要使用两个 location
块)。
可以在文档中找到用于 tornado 的完整 nginx 配置:http://www.tornadoweb.org/en/stable/guide/running.html#running-behind-a-load-balancer