nginx 伺服器透過 https 使用所有可用的檔案句柄(upd:無限循環?)

nginx 伺服器透過 https 使用所有可用的檔案句柄(upd:無限循環?)

所以我有一個 nginx 伺服器,它透過 https 與 Sinatra 一起工作。當我嘗試在 Mongrel 和 http(無 s)上正常工作的配置中下載 jnlp 檔案時,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,ruby 1.9.1,nginx 0.8.40,openssl 1.0.0a,沒有任何變化。

編輯:罪魁禍首似乎是由於使用 SSL 而導致的無限重定向。我不知道如何解決這個問題,除了將 jnlp 檔案託管在伺服器的根目錄中(我不想這樣做,因為它限制我一次只能使用一個基於 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 移到 root 中避免了這個問題,因為由於 ssl,沒有任何代理。

那麼,該如何避免nginx中的無限proxy_pass循環呢?

答案1

nginx 正在偵聽連接埠 443 /uploader。看來您應該代理您的 sinatra 應用程序,該應用程式正在偵聽其他連接埠?我不太了解nginx,但看起來不太對勁。

相關內容