gpt4 book ai didi

python - 在不同端口上运行 Tornado 和托管应用程序

转载 作者:行者123 更新时间:2023-11-28 18:39:42 25 4
gpt4 key购买 nike

我有一个 Tornado 网络聊天,出于身份验证等各种原因,它必须绝对在默认端口 80 上运行。但是,Tornado 网络服务器运行在端口 8800 上,原因很明显(如果可以在同一端口上托管 Tornado端口作为我的网站,我愿意尝试),所以我想要完成的是通过我的控制台运行 Tornado Web 服务器,同时在我网站的默认端口上托管 Tornado 网络聊天。

我将网络聊天的 index.html 移动到我的网站默认文件夹中,因此它类似于 www.example.com/webchat.html 而不是 www.example.com:8800/webchat。然后我用命令运行 Tornado

python webchat.py 

但是当我访问 webchat.html 时,聊天并没有像在端口 8800 上那样运行,因为该页面未呈现 python。

网络聊天 HTML

<div class="container" style="width: auto; height: 100%;">

<span>{% raw content %}</span> <!-- The span is not rendered on page -->



</div><!-- /.container -->

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>

{% if 'chat' in globals() and chat %}
<!-- Application script -->
<script src="{{ static_url('stuff.js') }}" type="text/javascript"></script>
{% end %}

最佳答案

我可以建议两个选项:

  1. 如果您的网站是静态的,您可以放弃 apache 服务器,将您的网站移动到 tornado,并让 tornado 在 / 路径上为您的网站提供服务。然后在端口 80 上运行 tornado。这可能是最简单的。添加以下内容作为最后一个 Tornado 处理程序:

    (r'/(.*)', tornado.web.StaticFileHandler, {'path': static_path}),

    static_path 应该是您的 apache 服务的网站根目录的路径。

  2. 如果您需要 apache 服务器,则可以将 apache 配置为您的 tornado 服务器的反向代理。来自 Need help setting up: Apache Reverse Proxy ,看起来您需要将此添加到您的 apache.conf:

    ProxyPass/webchat http://localhost:8800/webchat
    ProxyPassReverse/webchat http://localhost:8800/webchat

    您还需要加载指定的 Apache 模块。

您也可以尝试使用 Tornado 的 WSGI 功能,然后使用 mod_wsgi 配置 Apache。

关于python - 在不同端口上运行 Tornado 和托管应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com