Nginx outputs incorrect website content when configuring reverse proxy

when I add proxy_set_header Host $host; , there is a multi-site configuration on the host pointed to by the reverse proxy. I expect to display the content of site A, but actually show the content of site B. I don"t know what the problem is. The following is my reverse proxy configuration.

user  www www;
worker_processes auto;
error_log  /home/wwwlogs/nginx_error.log  crit;
pid        /usr/local/nginx/logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }
http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        server_tokens off;
        access_log off;
        
include vhost/*.conf;

server
{
    listen 80;
    include /usr/local/nginx/conf/domainsA.txt;
    location /
    {
        proxy_set_header Host $host;-sharp 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://examplea.com/;
    }
    access_log  /home/wwwlogs/www_accessa.log;
}

server
{
    listen 80;
    include /usr/local/nginx/conf/domainsB.txt;
    location /
    {
        proxy_set_header Host $host;-sharp 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://exampleb.com/;
    }
    access_log  /home/wwwlogs/www_accessb.log;
}

/ usr/local/nginx/conf/domainsa.txt is as follows:

server_name example_a.com;

/ usr/local/nginx/conf/domainsb.txt is as follows:

server_name example_b.com;

result of running curl-I http://example_a.com:

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 02 Dec 2018 03:19:24 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
Vary: Accept-Encoding
X-Powered-By: PHP/7.2.6
Set-Cookie: PHPSESSID=qurm52c7jltd0quhvqud58nd2d; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache

there is no error log in the log directory.
I"ve been looking for a solution for a few days, hoping someone can help me.
my goal is to get the real domain name before the reverse proxy .
related questions

solution: I tried to modify the nginx configuration several times and found a configuration that was useful to me. I still don"t know the cause of the problem. Here is my configuration:

-sharp Host
proxy_set_header X-Real-HOST $host;
// php$_SERVER["HTTP_X_REAL_HOST"]host
Jan.17,2022

do not know whether it is helpful to others, the environment that this problem occurs is through nginx reverse proxy multiple sites on the same server, does not show the correct website, remove Host and replace with custom variables can display the correct website, I am using the lnmp1.5 button to install the environment, still do not know the cause of the problem, but now I can achieve my goal, record.


you are using proxy to domain name

proxy_pass http://exampleb.com/;

so proxy_set_header Host $host; this line doesn't work. You can try proxy_pass and specify ip

.

proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e49369-44d16.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e49369-44d16.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?