Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a flask application with mod_wsgi

I'm trying to deploy one of my Flask apps to mod_wsgi on apache, but I'm having trouble because apache tries to solve SOME of the routes on the filesystem:

apache's error_log:

[Mon Aug 06 19:18:38 2012] [error] [client ::1] File does not exist: 
/srv/http/webchat/src/_publish_message, referer: http://localhost:88/webchat/chat

I'm saying "SOME of the routes" because the authentication (on "/") and redirection to "/chat" works.

The route "_publish_message" is accessed via AJAX like this (using jQuery):

function publish_message(e){
    e.preventDefault();
    $.post('/_publish_message', {'message': "user's message taken from a text field"})
        .fail(Handler.publish_error);
}

The route "_sse_stream" is used as the URL for an EventSource.

These two aren't working!

The virtual host configuration:

<VirtualHost *:88>
    ServerName webchat.dev

    WSGIDaemonProcess webchat user=http group=http threads=5
    WSGIScriptAlias /webchat /srv/http/webchat/src/webchat.wsgi
    WSGIScriptReloading On

    DocumentRoot /srv/http/webchat/src

    <Directory /srv/http/webchat/src>
        WSGIProcessGroup webchat
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

The webchat.wsgi file:

import sys
sys.path.insert(0, '/srv/http/webchat/src')
from index import app as application

A basic "hello world" app deployed to mod_wsgi runs OK. My flask app, when run using the development server integrated into flask, behaves well.

like image 491
Paul Avatar asked Nov 03 '22 18:11

Paul


1 Answers

Use this link to follow the correct process. You have to use the $SCRIPT_ROOT variable.

flask.pocoo.org/docs/patterns/jquery

like image 148
codegeek Avatar answered Nov 09 '22 07:11

codegeek