Reputation: 3576
OK, so I am using nginx + php fastcgi, I need to show visitors an custom error page saying that the we are experiencing technical problems, how can I do that ?
Should I install nginx on 80 as proxy to another nginx server listening to 8080 and check it's status with HttpHealthcheck Module, or is there a better solution ?
Upvotes: 1
Views: 1818
Reputation: 607
You going to need an 3rd party addon to check your backend server, check this: http://wiki.nginx.org/HttpHealthcheckModule
When the backend is down, nginx answer an 502 error, you can set a custom page for it.
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
New answer :)
I would use haproxy(http://haproxy.1wt.eu/) for that.
haproxy as your frontend listening on port 80, and nginx+php-fpm as backend
installing HAProxy: (verify your settings and edit the scripts)
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 (I didn´t include the global/default sessions)
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
Check hatop util (http://code.google.com/p/hatop/) or include an stats session to haproxy.cfg so you can check on haproxy status...
listen stats :<port>
balance
mode http
stats enable
stats auth admin:admin
stats uri /
# option httplog
Configure php-fpm to respond the ping requests (or change it to other check)
On /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;
}
On /etc/php-fpm.d/www.conf include/uncomment
ping.path = /fpm_ping
ping.response = pong
Upvotes: 1