简体   繁体   中英

flask deploy with ec2 amazon and httpd

I want to deploy my flask application (who runs perfectly on localhost) , in an amazon EC2 server

this is my /etc/httpd/conf.d/wsgi.conf :

LoadModule wsgi_module modules/mod_wsgi.so


<VirtualHost *:80>
    ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/
    ServerAdmin  webmaster@dummy-host.example.com
    WSGIScriptAlias / /opt/i01/var/www/FlaskApp/flaskapp.wsgi
    <Directory /opt/i01/var/www/FlaskApp/FlaskApp/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /opt/i01/var/www/FlaskApp/FlaskApp/static
    <Directory /opt/i01/var/www/FlaskApp/FlaskApp/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog logs/i01.io-error_log
    CustomLog logs/i01.io-access_log common

</VirtualHost>

the flaskapp.wsgi :

import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/opt/i01/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = 'Add your secret key'

and my __init__.py :

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return "Hello, I love Digital Ocean!"
if __name__ == "__main__":
    app.run()

I have a configuration problem , but I don't found it

thank you for your answer , I fixed my problem the problem was just the WSGIPythonPath that wasn't defined

so I just added this line and it worked

WSGIPythonPath /opt/i01/var/www/FlaskApp/FlaskApp/venv/:/opt/i01/var/www/FlaskApp/FlaskApp/venv/lib/python2.7/site-packages

Your server name shouldn't have a trailing slash (ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/). It MUST not have a trailing slash if you are using name-based virtual hosts, because your browser's request won't be mapped to that VirtualHost.

Typically with mod_wsgi you'll set python-path to the site-packages directory of your virtualenv (if you have one).

(But you need to show any error log messages when you try to hit that vhost -- or say that there aren't any -- and indicate what response your browser gets. You should be able to test locally with a symlink from /opt/i01/var/www/ to your real directory. I'd add that in a comment but I have no karma to do so.)

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.

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