当用nginx作负载均衡的时候,nginx的配置文件以下:html
upstream server_pools { server 10.0.0.7:80 weight=1; server 10.0.0.8:80 weight=1;
当客户端访问时出现报错以下:nginx
[root@lb02 ~]# curl www.hahaetiantian.org <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> </p> <p>Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.</p> </body></html> [root@lb02 ~]# curl www.hahaetiantian.org www
查看日志报错并不能找到缘由,可是根据400报错以及对http协议的原理了解得知是由于请求头的缘由,最后在网上找到解决办法,缘由是由于upstream后面的名称有下划线使得代理没法识别,修改以下:apache
upstream server-pools { server 10.0.0.7:80 weight=1; server 10.0.0.8:80 weight=1;
而后再次访问结果以下:负载均衡
[root@lb02 ~]# curl www.etiantian.org apache www [root@lb02 ~]# curl www.etiantian.org www