librelist archives

« back to archive

Apache Server configuration problems

Apache Server configuration problems

From:
Karl McAuley
Date:
2011-06-28 @ 16:21
Hello,

I've been reading the flask documents about apache, and it seems to be
saying that I need to name every python application the server will be
running. As we have about a dozen python apps and more being added
this would be inconvenient.

I have gotten apache working with mod_wsgi, using this virtual host:

Listen 5000
<VirtualHost *:5000>
 ServerName xxx.xxx.xxx:5000


  WSGIScriptAlias /wsgi/ /data/httpd/wsgi/

 DocumentRoot /data/httpd/wsgi/
 <Directory "/data/httpd/wsgi">
   Options Indexes FollowSymLinks MultiViews ExecCGI
   AllowOverride All
   Order allow,deny
   Allow from All

   Addhandler wsgi-script .wsgi

 </Directory>

 ErrorLog /var/log/apache2/error_log_wsgi
 CustomLog /var/log/apache2/access_log_wsgi combined

 TypesConfig /etc/apache2/mime.types
 Include /etc/apache2/conf.d/*.conf
 DirectoryIndex index.php index.htm index.html index.py index.wsgi
 AccessFileName .htaccess

</VirtualHost>

but when I try the test code from the flask front page (flask is easy):


from flask import Flask
app = Flask(__name__)

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

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


I get the following error in the log:

 mod_wsgi (pid=13501): Target WSGI script '/data/httpd/wsgi/test.wsgi'
does not contain WSGI application 'application'.


Can anyone help. I've spent most of the day on this and have gotten
nowhere, and I'm keen to move off mod_python

Thanks
Karl

Re: [flask] Apache Server configuration problems

From:
Wilson Xu
Date:
2011-06-29 @ 12:01
This is my wsgi file.

#!/usr/bin/python

activate_this = '/home/wilson/app/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os, sys

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

if path not in sys.path:
    sys.path.append(path)

from main import app
application = app

// EOF

I think you should assign the flask app object  to 'application' to make it
work.

On Wed, Jun 29, 2011 at 12:21 AM, Karl McAuley <karl.mcauley@gmail.com>wrote:

> Hello,
>
> I've been reading the flask documents about apache, and it seems to be
> saying that I need to name every python application the server will be
> running. As we have about a dozen python apps and more being added
> this would be inconvenient.
>
> I have gotten apache working with mod_wsgi, using this virtual host:
>
> Listen 5000
> <VirtualHost *:5000>
>  ServerName xxx.xxx.xxx:5000
>
>
>  WSGIScriptAlias /wsgi/ /data/httpd/wsgi/
>
>  DocumentRoot /data/httpd/wsgi/
>  <Directory "/data/httpd/wsgi">
>   Options Indexes FollowSymLinks MultiViews ExecCGI
>   AllowOverride All
>   Order allow,deny
>   Allow from All
>
>   Addhandler wsgi-script .wsgi
>
>  </Directory>
>
>  ErrorLog /var/log/apache2/error_log_wsgi
>  CustomLog /var/log/apache2/access_log_wsgi combined
>
>  TypesConfig /etc/apache2/mime.types
>  Include /etc/apache2/conf.d/*.conf
>  DirectoryIndex index.php index.htm index.html index.py index.wsgi
>  AccessFileName .htaccess
>
> </VirtualHost>
>
> but when I try the test code from the flask front page (flask is easy):
>
>
> from flask import Flask
> app = Flask(__name__)
>
> @app.route("/")
> def hello():
>    return "Hello World!"
>
> if __name__ == "__main__":
>    app.run()
>
>
> I get the following error in the log:
>
>  mod_wsgi (pid=13501): Target WSGI script '/data/httpd/wsgi/test.wsgi'
> does not contain WSGI application 'application'.
>
>
> Can anyone help. I've spent most of the day on this and have gotten
> nowhere, and I'm keen to move off mod_python
>
> Thanks
> Karl
>



-- 
Think and code @ imwilsonxu.net

Re: [flask] Apache Server configuration problems

From:
Karl McAuley
Date:
2011-06-29 @ 14:31
Hello,
Thanks to everyone who replied, I think I am getting to grips with
this now, but how do I change the header so that I can output
Content-Type: text/xml?. Here is my code thus far:

from flask import Flask, request
application = Flask(__name__)

def WSerrorTextHTML(txt):
    err = "<p>ERROR!</p>"
    err += "<pre>"+ txt + "</pre>"
    return err

@application.route('/', methods=['POST', 'GET'])
def indexApp():

    try:
        # the imports and things I want to do to do go here
        import myXMLthing
        xmlThing = XMLthing()
        return xmlThing.xmlStuff(request)
    except:
        # For development I want to send error messages to the browser.
        import traceback
        return WSerrorTextHTML(traceback.format_exc())

    return "<p>nothing?</p>"

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


Karl.


On 29 June 2011 13:01, Wilson Xu <im.wilson.xu@gmail.com> wrote:
> This is my wsgi file.
> #!/usr/bin/python
> activate_this = '/home/wilson/app/env/bin/activate_this.py'
> execfile(activate_this, dict(__file__=activate_this))
> import os, sys
> path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> if path not in sys.path:
>     sys.path.append(path)
> from main import app
> application = app
> // EOF
> I think you should assign the flask app object  to 'application' to make it
> work.
>
> --
> Think and code @ imwilsonxu.net
>

Re: [flask] Apache Server configuration problems

From:
JimG
Date:
2011-06-28 @ 16:22
what is the content of /data/httpd/wsgi/test.wsgi ?

On 28 June 2011 17:21, Karl McAuley <karl.mcauley@gmail.com> wrote:

> Hello,
>
> I've been reading the flask documents about apache, and it seems to be
> saying that I need to name every python application the server will be
> running. As we have about a dozen python apps and more being added
> this would be inconvenient.
>
> I have gotten apache working with mod_wsgi, using this virtual host:
>
> Listen 5000
> <VirtualHost *:5000>
>  ServerName xxx.xxx.xxx:5000
>
>
>  WSGIScriptAlias /wsgi/ /data/httpd/wsgi/
>
>  DocumentRoot /data/httpd/wsgi/
>  <Directory "/data/httpd/wsgi">
>   Options Indexes FollowSymLinks MultiViews ExecCGI
>   AllowOverride All
>   Order allow,deny
>   Allow from All
>
>   Addhandler wsgi-script .wsgi
>
>  </Directory>
>
>  ErrorLog /var/log/apache2/error_log_wsgi
>  CustomLog /var/log/apache2/access_log_wsgi combined
>
>  TypesConfig /etc/apache2/mime.types
>  Include /etc/apache2/conf.d/*.conf
>  DirectoryIndex index.php index.htm index.html index.py index.wsgi
>  AccessFileName .htaccess
>
> </VirtualHost>
>
> but when I try the test code from the flask front page (flask is easy):
>
>
> from flask import Flask
> app = Flask(__name__)
>
> @app.route("/")
> def hello():
>    return "Hello World!"
>
> if __name__ == "__main__":
>    app.run()
>
>
> I get the following error in the log:
>
>  mod_wsgi (pid=13501): Target WSGI script '/data/httpd/wsgi/test.wsgi'
> does not contain WSGI application 'application'.
>
>
> Can anyone help. I've spent most of the day on this and have gotten
> nowhere, and I'm keen to move off mod_python
>
> Thanks
> Karl
>

Re: [flask] Apache Server configuration problems

From:
Karl McAuley
Date:
2011-06-28 @ 16:26
Hello Jim
its the 'hello world' code of the flask front page, I've tried various
paths in the @app.route("/") with no results :

from flask import Flask
app = Flask(__name__)

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

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

On 28 June 2011 17:22, JimG <j.gumbley@gmail.com> wrote:
> what is the content of /data/httpd/wsgi/test.wsgi ?
>
> On 28 June 2011 17:21, Karl McAuley <karl.mcauley@gmail.com> wrote:
>>
>> Hello,
>>
>> I've been reading the flask documents about apache, and it seems to be
>> saying that I need to name every python application the server will be
>> running. As we have about a dozen python apps and more being added
>> this would be inconvenient.
>>
>> I have gotten apache working with mod_wsgi, using this virtual host:
>>
>> Listen 5000
>> <VirtualHost *:5000>
>>  ServerName xxx.xxx.xxx:5000
>>
>>
>>  WSGIScriptAlias /wsgi/ /data/httpd/wsgi/
>>
>>  DocumentRoot /data/httpd/wsgi/
>>  <Directory "/data/httpd/wsgi">
>>   Options Indexes FollowSymLinks MultiViews ExecCGI
>>   AllowOverride All
>>   Order allow,deny
>>   Allow from All
>>
>>   Addhandler wsgi-script .wsgi
>>
>>  </Directory>
>>
>>  ErrorLog /var/log/apache2/error_log_wsgi
>>  CustomLog /var/log/apache2/access_log_wsgi combined
>>
>>  TypesConfig /etc/apache2/mime.types
>>  Include /etc/apache2/conf.d/*.conf
>>  DirectoryIndex index.php index.htm index.html index.py index.wsgi
>>  AccessFileName .htaccess
>>
>> </VirtualHost>
>>
>> but when I try the test code from the flask front page (flask is easy):
>>
>>
>> from flask import Flask
>> app = Flask(__name__)
>>
>> @app.route("/")
>> def hello():
>>    return "Hello World!"
>>
>> if __name__ == "__main__":
>>    app.run()
>>
>>
>> I get the following error in the log:
>>
>>  mod_wsgi (pid=13501): Target WSGI script '/data/httpd/wsgi/test.wsgi'
>> does not contain WSGI application 'application'.
>>
>>
>> Can anyone help. I've spent most of the day on this and have gotten
>> nowhere, and I'm keen to move off mod_python
>>
>> Thanks
>> Karl
>
>

Re: [flask] Apache Server configuration problems

From:
JimG
Date:
2011-06-28 @ 16:34
That wsgi file is a bit weird. Its basically a python syntax file, where
wsgi reaches in and looks for a WSGI app called 'application'.

http://werkzeug.pocoo.org/docs/deployment/mod_wsgi/

Try changing the name of the 'app' variable to 'application'.

Although you don't want too much stuff in that wsgi file, so typically you
would do something like:

from myapp import app as application

I.e. just use the wsgi file to import your flask app and call it
'application'.

Hope that works out for you.

Cheers, Jim.

On 28 June 2011 17:26, Karl McAuley <karl.mcauley@gmail.com> wrote:

> Hello Jim
> its the 'hello world' code of the flask front page, I've tried various
> paths in the @app.route("/") with no results :
>
> from flask import Flask
> app = Flask(__name__)
>
> @app.route("/")
> def hello():
>   return "Hello World!"
>
> if __name__ == "__main__":
>   app.run()
>
> On 28 June 2011 17:22, JimG <j.gumbley@gmail.com> wrote:
> > what is the content of /data/httpd/wsgi/test.wsgi ?
> >
> > On 28 June 2011 17:21, Karl McAuley <karl.mcauley@gmail.com> wrote:
> >>
> >> Hello,
> >>
> >> I've been reading the flask documents about apache, and it seems to be
> >> saying that I need to name every python application the server will be
> >> running. As we have about a dozen python apps and more being added
> >> this would be inconvenient.
> >>
> >> I have gotten apache working with mod_wsgi, using this virtual host:
> >>
> >> Listen 5000
> >> <VirtualHost *:5000>
> >>  ServerName xxx.xxx.xxx:5000
> >>
> >>
> >>  WSGIScriptAlias /wsgi/ /data/httpd/wsgi/
> >>
> >>  DocumentRoot /data/httpd/wsgi/
> >>  <Directory "/data/httpd/wsgi">
> >>   Options Indexes FollowSymLinks MultiViews ExecCGI
> >>   AllowOverride All
> >>   Order allow,deny
> >>   Allow from All
> >>
> >>   Addhandler wsgi-script .wsgi
> >>
> >>  </Directory>
> >>
> >>  ErrorLog /var/log/apache2/error_log_wsgi
> >>  CustomLog /var/log/apache2/access_log_wsgi combined
> >>
> >>  TypesConfig /etc/apache2/mime.types
> >>  Include /etc/apache2/conf.d/*.conf
> >>  DirectoryIndex index.php index.htm index.html index.py index.wsgi
> >>  AccessFileName .htaccess
> >>
> >> </VirtualHost>
> >>
> >> but when I try the test code from the flask front page (flask is easy):
> >>
> >>
> >> from flask import Flask
> >> app = Flask(__name__)
> >>
> >> @app.route("/")
> >> def hello():
> >>    return "Hello World!"
> >>
> >> if __name__ == "__main__":
> >>    app.run()
> >>
> >>
> >> I get the following error in the log:
> >>
> >>  mod_wsgi (pid=13501): Target WSGI script '/data/httpd/wsgi/test.wsgi'
> >> does not contain WSGI application 'application'.
> >>
> >>
> >> Can anyone help. I've spent most of the day on this and have gotten
> >> nowhere, and I'm keen to move off mod_python
> >>
> >> Thanks
> >> Karl
> >
> >
>

Re: [flask] Apache Server configuration problems

From:
Lars Hansson
Date:
2011-06-28 @ 21:25
Try adding the directory of your application to sys.path, like this:

#
import sys
import os

sys.path.insert(0, "/usr/local/src/myapp")
from myapp import app as application


Cheers,
Lars Hansson