connecting to flask app over VPN

2020-07-24 05:56发布

问题:

I am new to Flask and please do not mind if the problem sounds trivial. I have a Flask app (not written by me) which works fine from the local machine as well as remote machines as well when I am directly connected to the network.

But when I connect to the app over VPN it doesn't work. I am able to ssh on that machine as well as access other servers running on the same machine. It is a physical machine and not a VM

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')

I am running latest Flask version and python 2.7. Can anyone please suggest what may be wrong here ?

回答1:

It seems that you want to access to local enabled flask over another network. 0.0.0.0 ip is to connect to flask from different machines, but in the same network range. so if your IP isn't in the same range, this fails.

if you want to access your web page from the internet, you should consider to deploy your webapp.



标签: python flask