I'm trying to deploy a simple Flask app on EC2. Everything works fine, but when I try to access to my site I get a 404 error that says:
The requested URL /flaskapp.py/flaskapp.wsgi/ was not found on this server.
flaskapp.py code:
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:
import sys
sys.path.insert(0, '/var/www/html/flaskapp')
from flaskapp import app as application
And finally the file 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. I used the sample configuration that I found in the Flask documentation pdf with gunicorn web server, easiest way!
Simplest way to run a basic Flask app om EC2 :
1) application = app = Flask(--name--underscore as usual) .... .... application.run()
2) save the file as "application.py"
3) Zip the project with requirement.txt and upload the zip file through AWS EB concole.
It will run.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.