0

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  [email protected]
    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

1
  • The path of /opt/i01/var/www/FlaskApp/FlaskApp/ to the first Directory blocks appears wrong. Should be just /opt/i01/var/www/FlaskApp as that is the directory the WSGI script file is in. Commented May 6, 2015 at 3:00

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.)

1 Comment

The python-path option would only be relevant to mod_wsgi daemon mode which they aren't using. The python-path option also isn't the preferred way of referring to a virtual environment. For more details see blog.dscpl.com.au/2014/09/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.