1. 程式人生 > >nginx反向代理報錯400

nginx反向代理報錯400

當用nginx做負載均衡的時候,nginx的配置檔案如下:

    upstream server_pools {
         server 10.0.0.7:80  weight=1;
         server 10.0.0.8:80  weight=1;

當客戶端訪問時出現報錯如下:

[[email protected] ~]# 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>
[
[email protected]
~]# curl www.hahaetiantian.org www

檢視日誌報錯並不能找到原因,但是根據400報錯以及對http協議的原理了解得知是因為請求頭的原因,最後在網上找到解決辦法,原因是因為upstream後面的名稱有下劃線使得代理無法識別,修改如下:

    upstream server-pools {
         server 10.0.0.7:80  weight=1;
         server 10.0.0.8:80  weight=1;

然後再次訪問結果如下:

[[email protected] ~]# curl  www.etiantian.org
apache www
[
[email protected]
~]# curl www.etiantian.org www