Why does Nginx reverse proxy multiple sites and access the same site?

1.Nginx reverse proxies multiple sites and accesses the same site.
192.157.1.1 places multiple sites (for example, website1.com website2.com,.)

192.157.1.1 strong 80 nginx listen and forward to 127.0.0.1 strong 8000
192.157.1.1 strong 8000 APACHE snooping. Http requests forwarded by nginx are generally handled.
192.157.1.2 web 8000 other servers listen

  • case 1: configure a server segment, (server_name localhost) so that all 127sites can be accessed normally.
  • case 2: configure two server segments with the default server unchanged, insert a server segment in front of it (pointing to other servers), and all sites access the inserted server segment site.
  • case 3: configure two server segments, with the default server unchanged, and append a server segment (pointing to other servers). All sites access the sites configured by the first server segment by default.
  • case 4: miraculously, insert an additional server segment in front of it, that is, insert two server segments, and the last side is a default. The second inserted server segment is one of the sites that exist in the default server segment, such as website1.com,. At this time, all 127s of apache sites are accessible, including website1.com, and other server sites configured are also accessible.

I want to know why? In the first case, nginx is handled normally.
in the second case, it is normal for nginx to match the domain name of the first site, but it does not match the domain name of the first site, so why not go down and enter the default configuration segment?
in the third case, the request is forwarded to port 127.0.0.1 nginx 8000 before matching to the direct domain name. Similarly, do not continue the downward matching execution.
in the fourth case, it is puzzling why all sites return to normal after adding two server,.

2.nginx.conf

...

http{
    include       mime.types;
    default_type  application/octet-stream;
    
...

    include /usr/local/nginx/vhost/*.conf;-sharp1-sharp
    
    server {
            listen       80;
            server_name  localhost;
    
            -sharpcharset koi8-r;
    
            -sharpaccess_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
                proxy_pass http://local_to_httpd;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Real-IP $remote_addr;
            }
    }
    
    include /usr/local/nginx/vhost/*.conf;-sharp2-sharp

...

}
...

vhost/*.conf (when there is only one file in the vhost directory, for example: test.conf)
is roughly as follows

server {
        listen       80;
        server_name www.test.com;
        index index.html index.htm index.php;
        root  /mnt/web/test/wwwroot;

        set_real_ip_from 10.0.0.0/16;
        real_ip_header proxy_protocol;

        location / {
            index  index.html index.htm;
            proxy_pass http://test-other.com:8000;-sharp
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
        }

        -sharpaccess_log  /mnt/web/test/log/access.log test.log.format;
        error_log  /mnt/web/test/log/error.log;
}

when there are two configuration files

test.conf = > test.com
website1.conf = > website1.conf

access is fine.

Please everyone, there is an understanding of the answer, thank you!

Mar.14,2021
Menu