我使用fastcgi启动并使用lighttpd运行我的烧瓶应用程序,除了我的所有多级(例如/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
我得到了烧瓶的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)
答案 0 :(得分:0)
结果" /"因为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
))
)
}