:::

Pound反向代理伺服器延長等待時間的設定

布丁布丁吃布丁

Pound反向代理伺服器延長等待時間的設定

20091027_itmedia_ie

(圖片來源:ITmediaサイトが見れない・・・「The service is not available. Please try again later.」)

安裝Pound作為反向代理伺服器(reverse proxy)之後,服務就常常遇到以下錯誤訊息:

The service is not available. Please try again later.

這是因為網站運作時間超過了Pound預設的等待時間,所以Pound顯示了錯誤的訊息。以下教大家如何設定Pound的等待時間以避免這個問題。

After using Pound as reverse proxy, it’s very easy encounter this error:“The service is not available. Please try again later.” Following I will show you how to configure Pound’s TimeOut setting to prevent this problem.


Pound設定檔位置 / The path of Pound’s configuration file

要調整等待時間,必須調整Pound的設定檔。

一般Pound設定檔的位置是在 /etc/pound/pound.cfg,但是IPFire中Pound設定檔的位置是 /etc/pound.cfg

若要以vim開啟Pound設定檔的指令如下:

   1: # vim /etc/pound/pound.cfg

原本的pound.cfg的設定大概是:

   1: ## Minimal sample pound.cfg
   2: ##
   3: ## see pound(8) for details
   4:  
   5:  
   6: ######################################################################
   7: ## global options:
   8:  
   9: User            "www-data"
  10: Group           "www-data"
  11: #RootJail       "/chroot/pound"
  12:  
  13: ## Logging: (goes to syslog by default)
  14: ##      0       no logging
  15: ##      1       normal
  16: ##      2       extended
  17: ##      3       Apache-style (common log format)
  18: LogLevel        1
  19:  
  20: ## check backend every X secs:
  21: Alive           300
  22:  
  23: ## use hardware-accelleration card supported by openssl(1):
  24: #SSLEngine      "<hw>"
  25:  
  26: # poundctl control socket
  27: Control "/var/run/pound/poundctl.socket"
  28:  
  29: ## (... Others)

加入TimeOut的設定 / TimeOut configuration

Pound預設的等待時間只有15秒,我建議把它改成300秒,也就是超過5分鐘才顯示錯誤訊息。

那就要在設定檔中加入TimeOut設定:(注意O是大寫)

   1: ## Wait for server respond in X secs:
   2: TimeOut         300

於是設定檔開頭就會是:(注意紅字的部份

   1: ## Minimal sample pound.cfg
   2: ##
   3: ## see pound(8) for details
   4:  
   5:  
   6: ######################################################################
   7: ## global options:
   8:  
   9: User            "www-data"
  10: Group           "www-data"
  11: #RootJail       "/chroot/pound"
  12:  
  13: ## Logging: (goes to syslog by default)
  14: ##      0       no logging
  15: ##      1       normal
  16: ##      2       extended
  17: ##      3       Apache-style (common log format)
  18: LogLevel        1
  19:  
  20: ## check backend every X secs:
  21: Alive           300
  22:  
  23: ## Wait for server respond in X secs:
  24: TimeOut 300
  25:  
  26: ## use hardware-accelleration card supported by openssl(1):
  27: #SSLEngine      "<hw>"
  28:  
  29: # poundctl control socket
  30: Control "/var/run/pound/poundctl.socket"
  31:  
  32: ## (... Others)

重新啟動 Pound / Restart Pound Service

重新啟動的指令為:

   1: # /etc/init.d/pound restart

這樣的話,只要伺服器運作不要超過五分鐘,那就不會出現錯誤訊息了。


結論:利用Pound優雅地處理錯誤訊息 / Conclusion: Handle HTTP error with Pound

許多人用Pound都會覺得預設的錯誤訊息:「The service is not available. Please try again later.」很醜,也很讓使用者難以確定接下來到底該怎麼做好。

其實Pound可以設定在發生錯誤時顯示其他網頁,設定可以參考Pound secure reverse proxy "how to"這篇文章中的The pound config file(這個範例也有設定TimeOut),重點摘錄如下:

   1: Err414 "/var/www/htdocs/error/generic_error_page"
   2: Err500 "/var/www/htdocs/error/generic_error_page"
   3: Err501 "/var/www/htdocs/error/generic_error_page"
   4: Err503 "/var/www/htdocs/error/generic_error_page"

因此當發生414(網址過長)500(內部伺服器錯誤)501(不支援的HTML方法)503(伺服器停止服務)錯誤時,就會顯示「/var/www/htdocs/error/generic_error_page」這個網頁。

image

為此我做了一個實驗室雲端平台的錯誤網頁,下載網址是: http://dl.dropboxusercontent.com/u/717137/20130914-error_page/error_example.html

Pound的功能十分強大,下次我再介紹如何利用Pound製作緊急啟動方案(Emergency)。

(more...)