I'm trying to run a basic helloworld with apache2 and mod_wsgi but depsite following the tutorial from flask documentation all i got is an error 500.
Everything is in /var/www/myapp
myapp.wsgi
from yourapplication import app as application
/etc/apache2/site-availables/default
<VirtualHost *:80>
ServerName mydomain
WSGIDaemonProcess myap user=web group=www-data threads=5
WSGIScriptAlias / /var/www/mydomain/myap.wsgi
<Directory /var/www/myapp>
WSGIProcessGroup myap
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
hello.py (flask app)
#!/usr/bin/env python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello():
return render_template('hello.html')
if __name__ == '__main__':
app.run()
First, you should configure some kind of logging so you can see the actual exception behind the 500 response.
Based on your code, you may be generating an ImportError in your WSGI file when you attempt to import app
from yourapplication
instead of hello
. Try:
from hello import app as application
You also have a couple of spots where you use myap
instead of myapp
, if what you posted here matches what's on your server. Either way, logging your errors should confirm it.
I notice 3 things:
Please make sure your code works using the Flask's webserver before trying to deploy to Apache. Your final code should look like this to work:
hello.wsgi
import sys
sys.path.insert(0, '/path/to/your/application')
from hello import app as application
httpd.conf
<VirtualHost *:80>
ServerName mydomain
WSGIDaemonProcess myapp user=web group=www-data threads=5
WSGIScriptAlias / /var/www/mydomain/myapp.wsgi
<Directory /var/www/mydomain>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
And finally, if any error occur you can track them in your Apache's folder, inside Logs/error_log. Turn on your debug mode in Flask as Graham said and you will see any error in your application and better explain here. Basically you just have to change this in your hello.py:
if __name__ == '__main__':
app.run(debug= True)
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.