Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hello World - Flask / Apache / mod_wsgi - no response from Apache

I am following the tutorial at http://www.enigmeta.com/2012/08/16/starting-flask/ to develop and deploy a simple flask app to Apache using mod_wsgi. I think I've narrowed it to a flaw in my Apache config. If I run helloflask.py from the command line, it works fine. I can access it via wget from another shell at localhost:5000, and I get the correct response. I also have other virtual hosts (non wsgi) up and running, so I know Apache is running and responding to other requests on port 80.

I have the following structure:

/sites/helloflask.mydomain.com
   /helloflask
      application.wsgi
      helloflask.py
      (rest of env from virtualenv)
   /log
      access.log
      error.log

helloflask.py:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

application.wsgi:

import os, sys, logging
logging.basicConfig(stream=sys.stderr)

PROJECT_DIR = '/sites/helloflask.mydomain.com/helloflask'

activate_this = os.path.join(PROJECT_DIR, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
sys.path.append(PROJECT_DIR)

from helloflask import app as application

Apache config: /etc/apache2/sites-available/helloflask.mydomain.com

<VirtualHost *:80>
  ServerName helloflask.mydomain.com

  WSGIDaemonProcess helloflask user=myuser group=myuser threads=5
  WSGIScriptAlias / /sites/helloflask.mydomain.com/helloflask/application.wsgi

  <Directory /sites/helloflask.mydomain.com/helloflask>
    WSGIProcessGroup helloflask
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
  </Directory>
  LogLevel warn
  ErrorLog /sites/helloflask.mydomain.com/log/error.log
  CustomLog /sites/helloflask.mydomain.com/log/access.log combined
</VirtualHost>

I enable the vhost, restart apache, and get no response from the browser. "Server not found", so no 500 response, nothing. No entries in the access / error logs (specific to this vhost). I do get the following in the overarching Apache error log each time I restart:

[Sat Jun 29 20:07:58 2013] [notice] caught SIGTERM, shutting down
[Sat Jun 29 20:07:59 2013] [warn] mod_wsgi: Compiled for Python/2.7.2+.
[Sat Jun 29 20:07:59 2013] [warn] mod_wsgi: Runtime using Python/2.7.3.
[Sat Jun 29 20:07:59 2013] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.6 with Suhosin-Patch mod_wsgi/3.3 Python/2.7.3 configured -- resuming normal operations

I'm wondering if those two [warn] lines indicating different versions of Python are my problem, but I don't know how or what to modify to fix it. Any suggestions are appreciated.

Thanks!

like image 337
David Avatar asked Jun 30 '13 03:06

David


1 Answers

What ip does helloflask.mydomain.com point to? Try adding

127.0.0.1    helloflask.mydomain.com    helloflask

To your hosts file, and pointing your web browser at

http://helloflask.mydomain.com
like image 107
Dustin Anderson Avatar answered Oct 20 '22 16:10

Dustin Anderson