我的python文件在fcgi中很有趣,没有问题,但是我的静态内容会产生404个错误。
我的fastcgi.conf:
server.modules += ( "mod_fastcgi" )
fastcgi.server = ("/" =>
((
"socket" => "/tmp/webxyz-fcgi.sock",
"bin-path" => "/opt/local/www/xyz/webxyz.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
alias.url = (
"/static" => "/opt/local/www/xyz/app/static"
)
url.rewrite-once = (
#"^(/static($|/.*))$" => "$1",
"^(/static.*)$" => "$1",
"^(/.*)$" => "/webxyz.fcgi$1"
)我打开了一些调试:
debug.log-request-handling = "enable"
debug.log-request-header-on-error = "enable"
debug.log-file-not-found = "enable"(虽然奇怪的是找不到的文件似乎没有做任何事情.)
下面是我在error.log中看到的关于一个静态文件的内容--所有其他文件都会产生类似的输出(下面的省略号是一组信息更少的条件块,它们仅以行号变化):
2014-04-27 15:20:24: (response.c.340) Request-URI : /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
2014-04-27 15:20:24: (response.c.341) URI-scheme : http
2014-04-27 15:20:24: (response.c.342) URI-authority : 75.101.102.25:8080
2014-04-27 15:20:24: (response.c.343) URI-path (raw) : /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
2014-04-27 15:20:24: (response.c.344) URI-path (clean): /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
2014-04-27 15:20:24: (response.c.345) URI-query :
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (response.c.249) run condition
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.273) 2 global/HTTPurl=~\.pdf$ nej
2014-04-27 15:20:24: (configfile-glue.c.530) 1 (uncached) result: unknown
...
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.467) HTTP["url"] ( /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js ) compare to \.pdf$
2014-04-27 15:20:24: (configfile-glue.c.530) 1 (uncached) result: false
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (response.c.339) -- splitting Request-URI
2014-04-27 15:20:24: (response.c.340) Request-URI : /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
2014-04-27 15:20:24: (response.c.341) URI-scheme : http
2014-04-27 15:20:24: (response.c.342) URI-authority : 75.101.102.25:8080
2014-04-27 15:20:24: (response.c.343) URI-path (raw) : /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
2014-04-27 15:20:24: (response.c.344) URI-path (clean): /static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
2014-04-27 15:20:24: (response.c.345) URI-query :
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (mod_access.c.135) -- mod_access_uri_handler called
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (mod_fastcgi.c.3626) handling it in mod_fastcgi
2014-04-27 15:20:24: (response.c.473) -- before doc_root
2014-04-27 15:20:24: (response.c.474) Doc-Root : /opt/local/www/htdocs
2014-04-27 15:20:24: (response.c.475) Rel-Path : /static
2014-04-27 15:20:24: (response.c.476) Path :
2014-04-27 15:20:24: (response.c.524) -- after doc_root
2014-04-27 15:20:24: (response.c.525) Doc-Root : /opt/local/www/htdocs
2014-04-27 15:20:24: (response.c.526) Rel-Path : /static
2014-04-27 15:20:24: (response.c.527) Path : /opt/local/www/htdocs/static
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (response.c.544) -- logical -> physical
2014-04-27 15:20:24: (response.c.545) Doc-Root : /opt/local/www/htdocs
2014-04-27 15:20:24: (response.c.546) Basedir : /opt/local/www/xyz/app/static
2014-04-27 15:20:24: (response.c.547) Rel-Path : /static
2014-04-27 15:20:24: (response.c.548) Path : /opt/local/www/xyz/app/static
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.537) 1 (cached) result: false
2014-04-27 15:20:24: (response.c.249) run condition
2014-04-27 15:20:24: (configfile-glue.c.579) === start of condition block ===
2014-04-27 15:20:24: (configfile-glue.c.273) 2 global/HTTPurl=~\.pdf$ nej
...它看到的最后一条路径是我的静态目录/opt/local/www/xyz/app/静力,其中包含bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js
我不知道为什么没有找到-权限很好:
sudo -u www cat /opt/local/www/xyz/app/static/bower_components/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.js按预期工作。
如有任何指导或建议,请见谅。
发布于 2014-04-30 22:16:11
好的。
因此,阅读这帖子,我发现我对werkzeug.contrib.fixers.CGIRootFix的使用导致我将fcgi的范围定义为"/",它优先于url并重写"/static“的规则。将fcgi服务器包装在一个条件下以排除以"/static“开头的对urls的请求,解决了不提供静态内容的问题。
下面是工作的fastcgi.conf:
server.modules += ( "mod_fastcgi" )
$HTTP["url"] !~ "^/static" {
fastcgi.server = ("/" =>
((
"socket" => "/tmp/webpdb-fcgi.sock",
"bin-path" => "/opt/local/www/xyz/webxyz.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
}
alias.url = (
"/static" => "/opt/local/www/xyz/app/static"
)
url.rewrite-once = (
#"^(/static($|/.*))$" => "$1",
"^(/static.*)$" => "$1",
"^(/.*)$" => "/webxyz.fcgi$1"
)https://stackoverflow.com/questions/23330014
复制相似问题