當用nginx做負載均衡的時候,nginx的配置文件如下:
upstream server_pools { server 10.0.0.7:80 weight=1; server 10.0.0.8:80 weight=1;
當客戶端訪問時出現(xiàn)報錯如下:
[root@lb02 ~]# curl www.hahaetiantian.org
Bad Request
Your browser sent a request that this server could not understand.
Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.
[root@lb02 ~]# curl www.hahaetiantian.org www
查看日志報錯并不能找到原因,但是根據(jù)400報錯以及對http協(xié)議的原理了解得知是因為請求頭的原因,最后在網上找到解決辦法,原因是因為upstream后面的名稱有下劃線使得代理無法識別,修改如下:
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