php - nginx 配置负载均衡的时候,设置自身也为均衡服务器之一时,访问自身时 400 错误..??
phpcn_u1582
phpcn_u1582 2017-05-16 13:08:15
[PHP讨论组]

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_u1582
phpcn_u1582

全部回复(4)
某草草

你看看nginx日志,是不是死循环了

怪我咯

这一定是死循环了

/var/log 下面找找
世界只因有你

你自己不是说了嘛,自己代理自己是什么意思哦,自己接收个请求再给自己,这不死循环吗,再者后台和代理的端口一样不冲突吗?

为情所困

你把后端服务端口和反向代理的监听端口区分开不要用同一个端口,不就可以了么
或者用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去处理不就分开了么

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号