搜尋

首頁  >  問答  >  主體

php - nginx 設定負載平衡的時候,設定自身也為均衡伺服器之一時,存取自身時 400 錯誤..??

nginx.conf設定檔

    upstream test.com {
        # ip_hash;
        server 127.0.0.1:80 weight=10;
        #server 192.168.1.116:80 weight=1;
        #server 116.62.19.122:80 weight=1;
    }
    
    server {
        listen 80;
        server_name test.com;
        root /var/Website/Test;
        index index.php index.html index.htm;
        charset utf-8;
        
        location / {
            proxy_pass http://test.com;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_buffering off;

            try_files $uri $uri/ /index.php?$query_string;
            autoindex on;
        }

        location ~ \.php(.*)$ {
            fastcgi_pass 127.0.0.1:8000;
            fastcgi_split_path_info ^(.+\.php)(/?.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            include fastcgi_params;
        }
    }

hosts檔案

結果如下:

這是什麼情況? ?求大神解決...

phpcn_u1582phpcn_u15822824 天前488

全部回覆(4)我來回復

  • 某草草

    某草草2017-05-16 13:10:15

    你看看nginx日誌,是不是死循環了

    回覆
    0
  • 怪我咯

    怪我咯2017-05-16 13:10:15

    這一定是死循環了

    /var/log 下面找找

    回覆
    0
  • 世界只因有你

    世界只因有你2017-05-16 13:10:15

    你自己不是說了嘛,自己代理自己是什麼意思哦,自己接收個請求再給自己,這不死循環嗎,再者後台和代理的端口一樣不衝突嗎?

    回覆
    0
  • 为情所困

    为情所困2017-05-16 13:10:15

    你把後端服務端口和反向代理的監聽端口區分開不要用同一個端口,不就可以了麼
    或者用server_name去區分走哪個server也行啊
    比如test.com 請求到192.168.1.100的80埠使用的是網域test.com訪問,你寫一個server用server_name test.com來接受請求,代理的時候用test1.com 然後在開一個server用server_name test1.com這樣子真實請求和代理請求由兩個server去處理不就分開了麼

    回覆
    0
  • 取消回覆