我开发了一个 Flask 应用程序,可以在我的笔记本电脑上完美运行 - 所有端点都可以完美运行,并且我还创建了几个与 Flask API 端点交互的 HTML 页面。
下一步是将其(永久)部署到 AWS EC2 (Ubuntu)。我已经按照本教程创建了一个 Flask 应用程序 https://plainenglish.io/community/deploying-a-flask-application-on-ec2-dab5d3 并且“hello world”完美运行。
我用自己的代码替换了 app.py,/ 端点再次工作正常 - 但没有其他端点可以,我不断收到 404 错误。
我一直在尝试缩小原因,但即使我创建了 /test 端点,它也不起作用(通过浏览器和公共 IP)并返回 404。如果我通过 SSH 连接到 EC2 并运行
curl HTTP://127.0.0.1:8000/test
它有效 - 我可以看到返回的 HTML。
我错过了什么?
这是当前的app.py:
from flask import Flask, render_template, request, make_response, jsonify
from flask_restful import Api, Resource, reqparse, abort, fields, marshal_with
from sqlalchemy import *
import pandas as pd
app = Flask(__name__)
api = Api(app)
@app.route("/")
def home_page():
return render_template("api_home.html")
@app.route('/test')
def testing_area():
return render_template('test.html')
@app.route('/custom1')
def custom1():
return render_template('custom_interface_1.html')
@app.route('/custom2')
def custom2():
return render_template('custom_interface_2.html')
@app.route('/custom3')
def custom3():
return render_template('custom_interface_3.html')
@app.route('/custom4')
def custom4():
return render_template('custom_interface_4.html')
if __name__ == "__main__":
app.run(debug=True)
允许附加到您的实例的安全组上的端口 8000。这就是为什么您可以在本地访问它,但不能从互联网访问。