重写使用 Flask Python 框架配置 Lighttpd 的问题
我已经使用其内置服务器运行和开发了 Flask 应用程序,没有发生任何事件。它运行得很好,而且非常顺利和有趣。不幸的是,Lighttpd 一如既往地部署起来很痛苦。我正在尽可能严格地遵循说明,但不幸的是,我的申请仍然无法成功。
这是到目前为止我的配置:
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
这是有效的,因为它显示主页,但不显示任何后续页面。
我的 Flask 应用程序中有几个 app.route 处理程序,我可以在客户端中使用一些 XHR 使用 GET 或 POST 来访问它们。
另外,这是我的 .fcgi 文件,只是为了确保这里没有任何明显的错误:
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from main import app
if __name__ == '__main__':
WSGIServer(app).run()
如果有人可以识别问题,那么 AJAX 不适用于应用程序的 URI(很可能是因为我的重写规则很不稳定) ,我真的很感激。预先感谢各位!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要手动 chdir 到应用程序运行的目录。
You need to chdir to the directory your application is running in manually.
我知道这个响应来自未来,但我遇到了类似的问题,并发现对我来说的解决方法是确保我在模板中使用
url_for
。希望你能弄清楚!
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!
我也有同样的问题。对我来说,解决方案是将其添加到 fcgi 文件中,
在主要功能之前:
确保在测试时清除浏览器缓存。
I had the same problem. For me the solution was to add this in the fcgi file,
just before the main function:
Make sure to clear your browser cache when you test.