You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EC2实例部署Flask应用无法接收HTTP请求求助

在EC2实例部署Flask应用无法接收HTTP请求的问题

我尝试在EC2实例上部署一个简单的Flask应用,但无法发送任何HTTP请求。已经尝试过调整安全组的IP和端口组合,但问题依然存在。应用在本地运行完全正常,以下是我的应用代码和安全组入站、出站规则截图,这个问题已经困扰我一周了,不知道该怎么推进。

import logging
import sys
import threading
from flask import Flask, request, jsonify
from main import mainfunction
import concurrent.futures
# Configure logging to capture output
app = Flask(__name__)

# Your asynchronous function that will be called
def process_client(client):
    # Redirect stdout to the console
    sys.stdout = sys.__stdout__
    # Create a thread to run mainfunction in the background
    thread = threading.Thread(target=mainfunction, args=(client,))
    thread.start()
    return "Processing client in the background..."

@app.route('/process', methods=['POST'])
def process():
    try:
        data = request.get_json()
        if 'client' in data:
            client = data['client']

            # Call the asynchronous function using asyncio
            result = process_client(client)

            return jsonify({'result': result})
        else:
            return jsonify({'error': 'Missing client data in request'}), 400
    except Exception as e:
        return jsonify({'error': str(e)}), 500

@app.route('/', methods=['GET'])
def status():
    return 'Server is listening'

if __name__ == '__main__':
    app.run(debug=True)

安全组规则截图

入站规则

入站规则

出站规则

出站规则

内容的提问来源于stack exchange,提问作者Nikhil Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:32:19