Mod_wsgi 无法在 Amazon Ec2 上加载我的 Python 服务器模块

问题描述 投票:0回答:1

大家好,我正在尝试将测试 Flask 项目部署到在 Amazon Ec2 上运行 Amazon Linux 2(centos rhel fedora) 的 Httpd (Apache) 服务器上。从我的 Apache 日志中我不断得到“

目标 WSGI 脚本 '/home/ssm-user/Test_Wan/FlaskApp/lado.wsgi' 无法作为 Python 模块加载。” 和 ImportError:没有名为 server 的模块

这是我在 Httpd 服务器主页上收到的错误消息

这是我的 FlaskApp 目录树

这是我的flask应用程序中的文件以及其中文件和文件夹的权限

这是我的lado.wsgi脚本

import sys
sys.path.insert(0, '/home/ssm- 
user/Test_Wan/FlaskApp/server.py')

from server import app as application

if __name__ == "__main__":
    application.run()

这是我的server.py文件

from flask import Flask,render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template(f"index.html")

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

这是我的 FlaskAPP 目录中的模板文件夹中的文件,并且有权限

这是我的 HTML 文件,位于 FlaskApp 内的模板文件夹中:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://fonts.googleapis.com/css2?family=Raleway" rel="stylesheet">
    <link rel="stylesheet" href="../static/css/styles.css">
</head>
<body>
<div class="wrapper">
    <div class="top">
        <div class="title"><h1>My Blog</h1></div>
    </div>
    <div class="content">
        <div class="card">
            <h2>Test Title</h2>
            <p class="text">Test Subtitle</p>
        </div>
    </div>
</div>
</body>
<footer>
    <p>Made with ♥️ in Lagos.</p>
</footer>
</html>

这是位于我的 FlaskApp 目录中的模板文件夹中的 .htaccess 文件

RewriteEngine On
RewriteBase /
RewriteRule ^(.*\.html)$ /home/ssm-user/Test_Wan/FlaskApp/lado.wsgi/$1

这是我的 lado.conf 文件,位于我的 /etc/http/conf.d 文件夹中

<VirtualHost *:80>
        ServerName 3.81.5x.xxx #(public IP of my EC2 instance)
        DocumentRoot /home/ssm-user/Test_Wan/FlaskApp

        WSGIDaemonProcess FlaskApp threads=5
        WSGIScriptAlias / /home/ssm-user/Test_Wan/FlaskApp/lado.wsgi

        <Directory /home/ssm-user/Test_Wan/FlaskApp>
                WSGIProcessGroup FlaskApp
                WSGIApplicationGroup %{GLOBAL}
                Require all granted
                AllowOverride All
                DirectoryIndex index.html

                # Additional settings for static files
                Options FollowSymLinks
                AllowOverride None
                Require all granted

        </Directory>

        Alias /templates /home/ssm-user/Test_Wan/FlaskApp/templates
        <Directory /home/ssm-user/Test_Wan/FlaskApp/templates>
                Options FollowSymLinks
                AllowOverride None
                Require all granted
        </Directory>

        ErrorLog /var/log/httpd/error.log
        CustomLog /var/log/httpd/access.log combined
</VirtualHost>
python apache flask amazon-ec2 mod-wsgi
1个回答
0
投票

尝试从

server.py
中删除
sys.path
,然后重试。
sys.path
应该是一个目录。

© www.soinside.com 2019 - 2024. All rights reserved.