代码之家  ›  专栏  ›  技术社区  ›  dlasalle

通过lighttpd fastcgi托管的flask返回404的多级别路径

  •  0
  • dlasalle  · 技术社区  · 7 年前

    我使用fastcgi在lighttpd中启动并运行了我的flask应用程序,除了我的所有多级(例如。, /foo/page2

    127.0.0.1本地主机:5080-[2017年9月6日:16:38:45+0000]“GET/page1 HTTP/1.1”200

    127.0.0.1本地主机:5080-[2017年9月6日:16:39:07+0000]“GET/foo/page2 HTTP/1.1”404

    我得到了flask的404错误处理程序,而不是lighttpd。

    通过运行应用程序时 flask run

    127.0.0.1--[2017年9月6日11:44:56]“GET/page1 HTTP/1.1”200

    127.0.0.1--[2017年9月6日11:44:56]“GET/foo/page2 HTTP/1.1”200

    我的 lighttpd.conf

    server.document-root = "/var/www/"
    
    server.port = 5080
    server.username = "foobar"
    server.groupname = "foobar"
    
    server.modules += (
        "mod_fastcgi",
        "mod_rewrite",
        "mod_alias",
        "mod_accesslog"
    )
    
    $HTTP["url"] !~ "^/static" {
        fastcgi.server = ("/" =>
            ((
                "socket" => "/tmp/foobar-fcgi.sock",
                "bin-path" => "/home/foobar/app.fcgi",
                "check-local" => "disable",
                "max-procs" => 1
            ))
        )
    }
    
    # give us debugging output
    fastcgi.debug = 1
    
    alias.url = (
        "/static" => "/var/www/static"
    )
    

    我的路线看起来像:

    PAGE = Blueprint("home", __name__)
    
    @PAGE.route("/page1", methods=["GET"])
    def page1_view():
        ...
    
    @PAGE.route("/foo/page2", methods=["GET"])
    def page2_view():
        ...
    

    app = Flask(__name__)
    
    app.register_blueprint(PAGE)
    
    1 回复  |  直到 4 年前
        1
  •  0
  •   dlasalle    7 年前

    事实证明,“/”作为fastcgi路由将匹配任何内容(例如,将匹配“/foo/”中的秒“/”。

    解决方法是更改fastcgi。服务器指令:

    $HTTP["url"] !~ "^/static" {
        fastcgi.server = ("" =>
            ((
                "socket" => "/tmp/foobar-fcgi.sock",
                "bin-path" => "/home/foobar/app.fcgi",
                "check-local" => "disable",
                "max-procs" => 1
            ))
        )
    }