nginx服务器通过https使用所有可用的文件句柄(upd:无限循环?)

所以我有一个nginx服务器,通过与Sinatra的https工作。 当我尝试在configuration中下载一个jnlp文件,该configuration在Mongrel和http(no s)上正常工作时,nginx服务器无法为该文件提供504错误。 随后检查日志指出,这个错误是由于溢出了可用的文件句柄数量,即“24:太多的打开的文件”。 运行

sudo lsof -p <nginx worker pid> 

给我一个巨大的文件列表,全部看起来像:

 nginx 1771 nobody 11u IPv4 10867997 0t0 TCP localhost:44704->localhost:https (ESTABLISHED) nginx 1771 nobody 12u IPv4 10868113 0t0 TCP localhost:https->localhost:44704 (ESTABLISHED) nginx 1771 nobody 13u IPv4 10868114 0t0 TCP localhost:44705->localhost:https (ESTABLISHED) nginx 1771 nobody 14u IPv4 10868191 0t0 TCP localhost:https->localhost:44705 (ESTABLISHED) nginx 1771 nobody 15u IPv4 10868192 0t0 TCP localhost:44706->localhost:https (ESTABLISHED) nginx 1771 nobody 16u IPv4 10868255 0t0 TCP localhost:https->localhost:44706 (ESTABLISHED) nginx 1771 nobody 17u IPv4 10868256 0t0 TCP localhost:44707->localhost:https (ESTABLISHED) nginx 1771 nobody 18u IPv4 10868330 0t0 TCP localhost:https->localhost:44707 (ESTABLISHED) nginx 1771 nobody 19u IPv4 10868331 0t0 TCP localhost:44708->localhost:https (ESTABLISHED) nginx 1771 nobody 20u IPv4 10868434 0t0 TCP localhost:https->localhost:44708 (ESTABLISHED) 

增加可以打开的文件的数量是没有帮助的,因为然后nginx正好超过了这个限制。 难怪,它看起来像在一个循环拉取所有可用的文件。

任何想法是怎么回事,以及如何解决?

编辑: nginx 0.7.63,Ubuntu的Linux,Sinatra 1.0

编辑2:这是有问题的代码。 这是sinatra服务jnlp,我终于想通了:

 get '/uploader' do #read in the launch.jnlp file theJNLP = "" File.open("/launch.jnlp", "r+") do |file| while theTemp = file.gets theJNLP = theJNLP + theTemp end end content_type :jnlp theJNLP end 

如果我通过Mongrel和http服务Sinatra,一切正常。 如果我通过https服务于Sinatra和nginx,我会得到上述错误。 网站的所有其他部分似乎是相同的。

编辑:我已经升级到乘客2.2.14,ruby1.9.1,nginx 0.8.40,openssl 1.0.0a,并没有改变。

编辑:由于使用SSL,罪魁祸首似乎是无限的redirect。 我不知道如何解决这个问题,除了在服务器的根目录下托pipejnlp文件(我宁愿不要这样做,因为它一次只限制一个基于jnlp的应用程序)。

来自nginx.conf的相关行:

 # HTTPS server # server { listen 443; server_name MyServer.org root /My/Root/Dir; passenger_enabled on; expires 1d; proxy_set_header X-FORWARDED_PROTO https; proxy_set_header X_FORWARDED_PROTO https;#the almighty google is not clear on which to use location /upload { proxy_pass https://127.0.0.1:443; } } 

有趣的是,首先,我把jnlp放到了一个名为'uploader'的目录中,而不是'upload',但是这仍然导致了这个问题,因为proxy_pass指令出现在日志中。 其次,再次将jnlp移动到根目录,避免了这个问题,因为没有任何ssl的代理。

那么,如何避免nginx中无限的proxy_pass循环呢?

nginx正在侦听端口443.当你得到/uploader的请求,你代理…端口443.这是nginx。 似乎你应该代理你的sinatra应用程序,这是在其他港口上听? 我不太了解nginx,但看起来不正确。