开发者

Rewrite issue with configuring Lighttpd with Flask Python framework

I've run and developed my Flask application without incident using its built-in server. It has worked fine and has been really smooth and fun. Unfortunately, Lighttpd is, as always, a pain to deploy to. I'm following the instructions as closely as I can, but unfortunately, my application still isn't working out.

Here is my configuration so far:

server.modules   += ( "mod_fastcgi" )
server.modules   += ( "mod_rewrite" )

fastcgi.server = ("/bioinfo/main.fcgi" =>
    ((
        "socket" => "/tmp/bioinfo-fcgi.sock",
        "bin-path" => "/var/www/bioinfo/main.fcgi",
        "check-local" => "disable",
        "max-procs" => 1
    ))
)
fastcgi.debug = 1

url.rewrite-once = (
    "^/bioinfo/static/(.*)$" => "/bioinfo/static/$1",
    "^/bioinfo/(.*)$" => "/bioinfo/main.fcgi/$1"
)

# in: /etc/lighttpd/conf-available/10-fastcgi.conf

This works in that it displays the main page, but not any subsequent pages.

I have several app.route handlers in my Flask application which I access开发者_如何学Python using either GET or POST using some XHR in the client.

Also, here's my .fcgi file, just to make sure I don't have any glaring errors here:

#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from main import app

if __name__ == '__main__':
    WSGIServer(app).run()

If anyone can identify the problem, being, AJAX doesn't work with the application's URIs (most likely because my rewrite rules are wonky), I'd really appreciate it. Thanks in advance, folks!


You need to chdir to the directory your application is running in manually.


I know this response comes from significantly in the future, but I ran into a similar issue and found that the fix for me was to make sure I was using url_for in my templates. Hope that you got it figured out!


I had the same problem. For me the solution was to add this in the fcgi file, just before the main function:

class ScriptNameStripper(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        environ['SCRIPT_NAME'] = ''
        return self.app(environ, start_response)

app = ScriptNameStripper(app)

Make sure to clear your browser cache when you test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜