Nginx_upstream实现:设置备份主机及过滤HTTP错误自动切除[8000=>Node服务器 || 2000=>默认错误处理页]:
C#代码
- #集群中的所有后台服务器的配置信息
- upstream nodeJs {
- #server 123.56.233.208 weight=10;
- #server 127.0.0.1:3000 weight=10;
- server 127.0.0.1:8000;
- server 127.0.0.1:2000 backup;
- }
- #调用所有的Server配置文件
- include /usr/local/nginx/conf/vhosts/*.conf;
- server {
- listen 3000;
- server_name liuxinxiu.com;
- add_header Proxy-By $upstream_http_server; #代理服务器Server
- location / {
- proxy_pass http://nodeJs; #反向代理到后端Server
- proxy_set_header Host $host:3000;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- #proxy_next_upstream error timeout invalid_header http_403 http_404;
- }
- }
Nginx=>2000端口默认错误处理页(相关配置):
C#代码
- server{
- listen 2000;
- server_name 127.0.0.1;
- index index.html index.htm index.php;
- root /ftp/www/2000;
- error_page 404 /index.html;
- }