【问题标题】:connecting to flask app over VPN通过 VPN 连接到烧瓶应用程序
【发布时间】:2017-07-03 15:50:52
【问题描述】:

我是 Flask 的新手,如果问题听起来微不足道,请不要介意。 我有一个 Flask 应用程序(不是我编写的),当我直接连接到网络时,它可以在本地机器和远程机器上正常工作。

但是当我通过 VPN 连接到应用程序时,它不起作用。我能够在该机器上 ssh 以及访问在同一台机器上运行的其他服务器。它是物理机,而不是虚拟机

app = Flask(__name__)

def loadAppVariables():
      mc = pylibmc.Client(["127.0.0.1"], binary=True,
      behaviors={"tcp_nodelay": True,
      "ketama": True});
      app.mc=mc

def initApp():
    app.fNet= {some object }
    mc = pylibmc.Client(["127.0.0.1"], binary=True,
    behaviors={"tcp_nodelay": True,
    "ketama": True});
    app.mc=mc;

@app.route('/classify', methods=['POST'])
def classify():
        # We will save the file to disk for possible data collection.
        imagefile = request.files['imagefile']
        processImageFile(imagefile)

@app.route('/')
def index():
    return render_template('cindex.html', has_result=False)

@app.before_request
def before_request():
    loadAppVariables()

@app.teardown_request
def teardown_request(exception):
    storeAppVariables()

if __name__ == '__main__':
    initApp();
    app.run(debug=False,host='0.0.0.0')

我正在运行最新的 Flask 版本和 python 2.7。谁能建议这里可能有什么问题?

【问题讨论】:

    标签: python flask


    【解决方案1】:

    您似乎想通过另一个网络访问本地启用的烧瓶。 0.0.0.0 ip 是连接不同机器的flask,但是在同一个网络范围内。因此,如果您的 IP 不在同一范围内,则会失败。

    如果你想从互联网访问你的网页,你应该考虑deploy你的webapp。

    【讨论】:

    • 非常感谢您的解释。我早上使用mod_wdgi 部署了它,它运行良好。
    猜你喜欢
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2015-04-09
    • 2021-01-20
    • 1970-01-01
    • 2012-04-22
    • 2023-03-08
    相关资源
    最近更新 更多