search

Home  >  Q&A  >  body text

php - When nginx configures load balancing and sets itself as one of the balancing servers, a 400 error occurs when accessing itself..??

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_u15822829 days ago497

reply all(4)I'll reply

  • 某草草

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

    Look at the nginx log, is it an infinite loop?

    reply
    0
  • 怪我咯

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

    This must be an endless loop

    /var/log 下面找找

    reply
    0
  • 世界只因有你

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

    Didn’t you say it yourself? What do you mean by proxying yourself? Isn’t this an endless loop? Isn’t this an endless loop? Doesn’t the port of the backend and the proxy also conflict?

    reply
    0
  • 为情所困

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

    Isn’t that enough if you separate the backend service port and the listening port of the reverse proxy and don’t use the same port? Or you can use server_name to distinguish which server to use. For example, test.com requests 192.168.1.100. Port 80 uses the domain name test.com to access. You write a server using server_name test.com to accept requests. When proxying, use test1.com. Then open a server using server_name test1.com. In this way, the real request and the proxy request are divided into two. Wouldn’t it be separated if we have a server to handle it?

    reply
    0
  • Cancelreply