简体   繁体   English

将 flask 应用程序部署到亚马逊 linux 2 ec2 实例

[英]deploy flask app to amazon linux 2 ec2 instance

I have seen lot of examples on how to deploy a Flask web app to AWS, but all of those examples are using Ubuntu or Red hat instances of the EC2.我已经看到很多关于如何将 Flask web 应用程序部署到 AWS 的示例,但所有这些示例都使用 Ubuntu 或 EC2 的 Red hat 实例。

Could any one give me the steps to deploy the flask app to an EC2 instantiated from an Amazon Linux 2 (free tier), and using Python3谁能给我将 flask 应用程序部署到从 Amazon Linux 2(免费层)实例化的 EC2 并使用 Python3 的步骤

update更新

David Buck, thanks for that link, but I am trying to use httpd with mod_wsgi;大卫巴克,感谢该链接,但我正在尝试将 httpd 与 mod_wsgi 一起使用; after going through so many google searches I came up with the following steps:经过这么多的谷歌搜索后,我想出了以下步骤:

yum install python3-devel httpd-devel gcc
pip3 install mod_wsgi
mod_wsgi-express module-config >> /etc/httpd/conf/httpd.conf

but with the last command I am getting mod_wsgi-express: command not found但是使用最后一个命令我得到mod_wsgi-express: command not found

once I pass the above step, I can continue with setting up the flask application通过上述步骤后,我可以继续设置 flask 应用程序

Thanks谢谢

I followed the following steps and got the flask application served from an amazon ec2 instance (Amazon Linux 2 AMI t2.micro)我按照以下步骤获得了从亚马逊 ec2 实例(Amazon Linux 2 AMI t2.micro)提供的 flask 应用程序

Login to the ec2 instance via ssh, and run the following commands:通过ssh登录ec2实例,运行以下命令:

01 sudo su
02 yum install python3-devel httpd-devel httpd gcc git
03 pip3 install mod_wsgi
04 mod_wsgi-express start-server

the above command didn't work, but it worked after restarting the instance上面的命令不起作用,但是重启实例后它起作用了

05 mod_wsgi-express module-config >> /etc/httpd/conf/httpd.conf

again this didn't work;这又没用; kept getting permission denier error, even when I run with sudo;即使我使用 sudo 运行,也会不断收到拒绝权限错误; so I piped to a temp file, and copied the contents of the temp file into the /etc/httpd/conf/httpd.conf所以我通过管道传输到一个临时文件,并将临时文件的内容复制到/etc/httpd/conf/httpd.conf

The contents of the temp file should like the following临时文件的内容应如下所示

LoadModule wsgi_module "/usr/local/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
WSGIPythonHome "/usr"

restart the http service and make sure everything is ok重启 http 服务并确保一切正常

06 systemctl restart httpd

now for setting up the flask application现在用于设置 flask 应用程序

07 pip3 install flask
08 car /var/www
09 git clone https://github.com/nshathish/flask-lab2.git
10 cd flask-lab2
11 nano flask-lab2.wsgi

enter the following contents into the above file在上述文件中输入以下内容

import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, "/var/www/flask-lab2")
from app import app as application


12 sudo nano /etc/httpd/conf.d/flask-lab2.conf

now copy the following content into the above file现在将以下内容复制到上述文件中

<VirtualHost *:80>
  ServerName flask-lab2.myserver.com
  ServerAdmin root@nshathish.com1
  WSGIScriptAlias / /var/www/flask-lab2/flask-lab2.wsgi
  WSGIDaemonProcess flask-lab2
  <Directory /var/www/flask-lab2>
      WSGIProcessGroup flask-lab2
      WSGIApplicationGroup %{GLOBAL}
      Order deny,allow
      Allow from all
  </Directory>
  ErrorLog /var/log/httpd/error.log
  LogLevel warn
  CustomLog /var/log/httpd/access.log combined
</VirtualHost>

final check最终检查

13 curl http://localhost

and if you got Hello World for the above command everything is working fine如果你得到上述命令的Hello World一切正常

if anyone can shed some light into why I couldn't run step 5, it would be really useful;如果有人能解释为什么我不能运行第 5 步,那将非常有用; also any improvements to the above steps are much welcome也非常欢迎对上述步骤进行任何改进

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

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