简体   繁体   English

在AWS EC2上部署Flask应用程序

[英]Deploy Flask app on AWS EC2

I'm trying to deploy a simple Flask app on EC2. 我正在尝试在EC2上部署一个简单的Flask应用程序。 Everything works fine, but when I try to access to my site I get a 404 error that says: 一切正常,但当我尝试访问我的网站时,我收到404错误,上面写着:

The requested URL /flaskapp.py/flaskapp.wsgi/ was not found on this server. 在此服务器上找不到请求的URL /flaskapp.py/flaskapp.wsgi/。

flaskapp.py code: flaskapp.py代码:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return "hello"

if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=80)

flaskapp.wsgi: flaskapp.wsgi:

import sys
sys.path.insert(0, '/var/www/html/flaskapp')

from flaskapp import app as application

And finally the file 000-default.conf 最后是文件000-default.conf

 <VirtualHost *:80>
    ServerAdmin webmaster@localhost 
    ServerName myServerHostname
    DocumentRoot /var/www/
    WSGIDaemonProcess flaskapp threads=5
    WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi

<Directory flaskapp>
    WSGIProcessGroup flaskapp
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
    </Directory>



    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined
    ServerSignature On


</VirtualHost>

Is this code wrong? 这段代码错了吗? What can I do to fix it? 我该怎么办才能修复它? Thanks to everyone! 谢谢大家!

I "solved" this problem using Nginx instead of Apache. 我使用Nginx而不是Apache“解决”了这个问题。 I used the sample configuration that I found in the Flask documentation pdf with gunicorn web server, easiest way! 我使用了我在Flask文档pdf中使用gunicorn web服务器找到的示例配置,最简单的方法!

Simplest way to run a basic Flask app om EC2 : EC2运行基本Flask应用程序的最简单方法:

1) application = app = Flask(--name--underscore as usual) .... .... application.run() 1)application = app = Flask( - name - 像往常一样下划线).... .... application.run()

2) save the file as "application.py" 2)将文件保存为“application.py”

3) Zip the project with requirement.txt and upload the zip file through AWS EB concole. 3)使用requirements.txt压缩项目并通过AWS EB concole上传zip文件。

It will run. 它会运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM