當用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