【问题标题】:Intermittent errors using lighttpd + mod_proxy使用 lighttpd + mod_proxy 的间歇性错误
【发布时间】:2012-03-11 09:30:36
【问题描述】:

我在嵌入式 linux 设备上运行 lighttpd v1.4.18。 Lighty 正在监听 80 端口并充当反向代理,以便将 _http://192.168.0.1/foo1 请求代理到 _http://127.0.0.1:11111

### 1st appreach
proxy.server = ( "^/foo1" => ( "" => ( "host" => "127.0.0.1", "port" => 11111 )))

### 2nd approach
$HTTP["url"] =~ "^/foo1" { 
    proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 11111 ))) 
}

基本上,这可以正常工作。但是我确实会随机遇到 404 错误,尤其是在启动后。如果后台服务“foo1”没有运行,我会收到一条 503 错误消息,这是有道理的。但是因为我可以查询 _http://192.168.0.1:11111 ,所以情况并非如此......设备已启动并运行“foo1”准备好为传入请求提供服务。那么,为什么使用 1st of 2nd 方法都会出现这些 404 错误?!

这就是日志所揭示的......

2012-03-05 08:31:36: (request.c.294) fd: 6 request-len: 164 
POST /foo1 HTTP/1.1
Host: 192.168.0.1
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 450
Connection: close
SOAPAction: ""


2012-03-05 08:31:36: (response.c.205) -- splitting Request-URI 
2012-03-05 08:31:36: (response.c.206) Request-URI  :  /foo1
2012-03-05 08:31:36: (response.c.207) URI-scheme   :  http 
2012-03-05 08:31:36: (response.c.208) URI-authority:  192.168.0.1 
2012-03-05 08:31:36: (response.c.209) URI-path     :  /foo1
2012-03-05 08:31:36: (response.c.210) URI-query    :   
2012-03-05 08:31:36: (response.c.260) -- sanatising URI 
2012-03-05 08:31:36: (response.c.261) URI-path     :  /foo1
2012-03-05 08:31:36: (mod_proxy.c.1080) proxy - start 
2012-03-05 08:31:36: (response.c.375) -- before doc_root 
2012-03-05 08:31:36: (response.c.376) Doc-Root     : /var/www 
2012-03-05 08:31:36: (response.c.377) Rel-Path     : /foo1
2012-03-05 08:31:36: (response.c.378) Path         :  
2012-03-05 08:31:36: (response.c.426) -- after doc_root 
2012-03-05 08:31:36: (response.c.427) Doc-Root     : /var/www 
2012-03-05 08:31:36: (response.c.428) Rel-Path     : /foo1
2012-03-05 08:31:36: (response.c.429) Path         : /var/www/foo1
2012-03-05 08:31:36: (response.c.446) -- logical -> physical 
2012-03-05 08:31:36: (response.c.447) Doc-Root     : /var/www 
2012-03-05 08:31:36: (response.c.448) Rel-Path     : /foo1
2012-03-05 08:31:36: (response.c.449) Path         : /var/www/foo1
2012-03-05 08:31:36: (response.c.466) -- handling physical path 
2012-03-05 08:31:36: (response.c.467) Path         : /var/www/foo1
2012-03-05 08:31:36: (response.c.523) -- file not found 
2012-03-05 08:31:36: (response.c.524) Path         : /var/www/foo1
2012-03-05 08:31:36: (response.c.114) Response-Header: 
HTTP/1.1 404 Not Found
Connection: close
Content-Type: text/html
Content-Length: 345
Date: Mon, 05 Mar 2012 07:31:36 GMT
Server: lighttpd

这就是我期望看到的......

2012-03-05 08:42:43: (request.c.294) fd: 6 request-len: 164 
POST /foo1 HTTP/1.1
Host: 192.168.0.1
User-Agent: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 450
Connection: close
SOAPAction: ""


2012-03-05 08:42:43: (response.c.205) -- splitting Request-URI 
2012-03-05 08:42:43: (response.c.206) Request-URI  :  /foo1 
2012-03-05 08:42:43: (response.c.207) URI-scheme   :  http 
2012-03-05 08:42:43: (response.c.208) URI-authority:  192.168.0.1
2012-03-05 08:42:43: (response.c.209) URI-path     :  /foo1 
2012-03-05 08:42:43: (response.c.210) URI-query    :   
2012-03-05 08:42:43: (response.c.260) -- sanatising URI 
2012-03-05 08:42:43: (response.c.261) URI-path     :  /foo1 
2012-03-05 08:42:43: (mod_proxy.c.1080) proxy - start 
2012-03-05 08:42:43: (mod_proxy.c.1116) proxy - ext found 
2012-03-05 08:42:43: (mod_proxy.c.1159) proxy - used fair balancing 
2012-03-05 08:42:43: (mod_proxy.c.1240) proxy - found a host 127.0.0.1 11111 
2012-03-05 08:42:43: (response.c.375) -- before doc_root 
2012-03-05 08:42:43: (response.c.376) Doc-Root     : /var/www 
2012-03-05 08:42:43: (response.c.377) Rel-Path     : /foo1 
2012-03-05 08:42:43: (response.c.378) Path         :  
2012-03-05 08:42:43: (response.c.426) -- after doc_root 
2012-03-05 08:42:43: (response.c.427) Doc-Root     : /var/www 
2012-03-05 08:42:43: (response.c.428) Rel-Path     : /foo1 
2012-03-05 08:42:43: (response.c.429) Path         : /var/www/foo1 
2012-03-05 08:42:43: (response.c.446) -- logical -> physical 
2012-03-05 08:42:43: (response.c.447) Doc-Root     : /var/www 
2012-03-05 08:42:43: (response.c.448) Rel-Path     : /foo1 
2012-03-05 08:42:43: (response.c.449) Path         : /var/www/foo1 
2012-03-05 08:42:43: (mod_proxy.c.377) connect delayed: 7 
2012-03-05 08:42:43: (mod_proxy.c.994) proxy: fdevent-out 1 
2012-03-05 08:42:43: (mod_proxy.c.805) proxy - connect - delayed success 
2012-03-05 08:42:43: (mod_proxy.c.961) proxy: fdevent-in 4 
2012-03-05 08:42:43: (mod_proxy.c.645) proxy - have to read: 607 
2012-03-05 08:42:43: (mod_proxy.c.961) proxy: fdevent-in 4 
2012-03-05 08:42:43: (mod_proxy.c.645) proxy - have to read: 0 
2012-03-05 08:42:43: (response.c.114) Response-Header: 
HTTP/1.1 200 OK
Connection: close
Server: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 490
Date: Mon, 05 Mar 2012 07:42:43 GMT

更新的版本会解决这个问题吗?还有其他建议吗?

提前非常感谢!

【问题讨论】:

  • 似乎lighty无法处理后台服务“foo1”可能被停止并重新启动的情况。如果 lighty 被配置为将代理反向到 foo1 暂时不可用,则出现问题。does

标签: lighttpd mod-proxy


【解决方案1】:

lighttpd 中的 mod_proxy 有很多错误并且不是那么可靠(例如上游和下游速度的大不匹配可能会使它绊倒,因为它缺乏流量控制)。话虽如此,您应该考虑使用比 1.4.18 更新的 lighttpd 版本 - 1.4.30 版本是当前版本。但是,即使是最新版本也可能会在您的特定网络上出错。

由于您处于嵌入式环境中,因此可能无法升级 lighttpd,因此您还可以尝试一些技巧,例如重复上游地址,以便 mod_proxy 在认为有错误时将“故障”转移到同一台服务器。您还可以使用 proxy.balance 配置,它的值是 fair, round-robinhash - 有时会有所帮助。

【讨论】:

  • 由于使用替代 proxy.balance 设置对我没有多大帮助,我将尝试 v1.4.30。不过,在嵌入式环境中,nginx 会是更好的选择吗?
  • 我使用 nginx 的次数不多,但我记得当我将它与 lighttpd 进行比较时,它的代理更可靠,因此它可能更适合您的目的。
猜你喜欢
  • 2012-08-13
  • 2016-05-20
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多