通过 lighttpd fastcgi returns 404 托管的烧瓶用于多级路径
flask hosted via lighttpd fastcgi returns 404's for mutlilevel paths
我已经启动了我的烧瓶应用程序并在 lighttpd 中使用 fastcgi 运行,它运行良好,除了我的所有多级(例如,/foo/page2
)路径导致 404 错误,但是单级路径工作正常(例如,/page1)。
127.0.0.1 localhost:5080 - [06/Sep/2017:16:38:45 +0000] "GET /page1 HTTP/1.1" 200
127.0.0.1 localhost:5080 - [06/Sep/2017:16:39:07 +0000] "GET /foo/page2 HTTP/1.1" 404
我得到了 flask 的 404 错误处理程序,而不是 lighttpd 的。
当 运行 通过 flask run
的应用程序时,多级路径工作正常。
127.0.0.1 - - [06/Sep/2017 11:44:56] "GET /page1 HTTP/1.1" 200
127.0.0.1 - - [06/Sep/2017 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)
事实证明“/”作为 fastcgi 路由将匹配任何内容(例如,将匹配“/foo/”中的秒数“/”)。
修复方法是将 fastcgi.server 指令更改为:
$HTTP["url"] !~ "^/static" {
fastcgi.server = ("" =>
((
"socket" => "/tmp/foobar-fcgi.sock",
"bin-path" => "/home/foobar/app.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
}
我已经启动了我的烧瓶应用程序并在 lighttpd 中使用 fastcgi 运行,它运行良好,除了我的所有多级(例如,/foo/page2
)路径导致 404 错误,但是单级路径工作正常(例如,/page1)。
127.0.0.1 localhost:5080 - [06/Sep/2017:16:38:45 +0000] "GET /page1 HTTP/1.1" 200
127.0.0.1 localhost:5080 - [06/Sep/2017:16:39:07 +0000] "GET /foo/page2 HTTP/1.1" 404
我得到了 flask 的 404 错误处理程序,而不是 lighttpd 的。
当 运行 通过 flask run
的应用程序时,多级路径工作正常。
127.0.0.1 - - [06/Sep/2017 11:44:56] "GET /page1 HTTP/1.1" 200
127.0.0.1 - - [06/Sep/2017 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)
事实证明“/”作为 fastcgi 路由将匹配任何内容(例如,将匹配“/foo/”中的秒数“/”)。
修复方法是将 fastcgi.server 指令更改为:
$HTTP["url"] !~ "^/static" {
fastcgi.server = ("" =>
((
"socket" => "/tmp/foobar-fcgi.sock",
"bin-path" => "/home/foobar/app.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
}