2011-10-24 41 views
1

好吧,所以我使用nginx + php fastcgi,我需要向訪問者顯示一個自定義錯誤頁面,表明我們遇到了技術問題,我該怎麼做?Nginx/Apache檢查另一個web服務器狀態(在線/離線)

我應該將80上的nginx作爲代理服務器安裝到另一臺監聽8080的nginx服務器上,並檢查它是否與HttpHealthcheck模塊狀態一致,還是有更好的解決方案?

回答

1

您將需要一個第三方插件來檢查你的後端服務器,檢查:http://wiki.nginx.org/HttpHealthcheckModule

當後端已關閉,nginx的回答一個502錯誤,你可以爲它設置的自定義頁面。

error_page 500 502 503 504 /50x.html; 
location = /50x.html { 
    root /usr/share/nginx/html; 
} 

新的答案:)

我會使用HAProxy的(http://haproxy.1wt.eu/)了點。

HAProxy的爲您的前端偵聽端口80和nginx的+ PHP-FPM作爲後端

安裝HAProxy的:(驗證您的設置和編輯腳本)

make TARGET=linux26 CPU=x86_64 
cp haproxy /usr/sbin/haproxy 
wget http://layer1.rack911.com/haproxy/haproxy-standard.cfg -O /etc/haproxy.cfg 
wget http://layer1.rack911.com/haproxy/haproxy.init -O /etc/init.d/haproxy 
chmod +x /etc/init.d/haproxy 

haproxy.cfg(我沒'T包括全球/默認會話)

frontend webserver-80 
     bind <ip>:80 
     option forwardfor 
     option http-server-close 
     default_backend backend-nginx 

backend backend-nginx 
     #balance roundrobin 
     balance source 
     option httpchk GET /fpm_ping 
     server srv1 <ip>:<port> weight 1 check 
     errorfile 503  /etc/errors/503_noserver.txt 

檢查hatop UTIL(http://code.google.com/p/hatop/)或包括統計會議haproxy.cfg這樣你就可以HAProxy的檢查統計我們...

listen stats :<port> 
     balance 
     mode http 
     stats enable 
     stats auth admin:admin 
     stats uri/
#  option httplog 

配置PHP-FPM以響應ping請求(或將其更改爲其他檢查)

在/etc/nginx/nginx.conf

location /fpm_ping { 
    access_log  off; 
    allow   <ipaddr/cidr>; 
    allow   127.0.0.1; 
    deny   all; 
    root   html; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; 
    include  fastcgi_params; 
} 

開/ etc/php-fpm.d/www.conf include/uncomment

ping.path = /fpm_ping 
ping.response = pong 
+0

我編輯了我的第一個問題,因爲情況有所改變,現在看看它。 – Eduard

+0

有用的貼子的人。我有一臺運行varnish/nginx/php-fpm的服務器。爲了監視狀態,我只使用uptimerobot,它工作正常,但它有幾個缺點。它只會檢查網站是啓動還是停止。這種方法帶來了更大的靈活性,因爲您可以查看所有http應用程序的狀態。我將設置一個小型的DotCould應用程序來監視狀態,並在事件發生時向我發送電子郵件。 –

相關問題