Nginx reverse proxies to another Nginx server and does not work properly

problem description

the first nginx server is configured with reverse proxy to a kibana server, and a second nginx direction proxy to the first nginx server. It is found that the first nginx cannot be accessed normally on the second nginx.

related codes

configuration of the first nginx reverse proxy
server_name: ng1

location / {
  proxy_pass http://kibana_server:8009;
  proxy_read_timeout 300;
  proxy_connect_timeout 300;
  proxy_redirect     off;

  proxy_set_header   X-Forwarded-Proto $scheme;
  proxy_set_header   Host              $http_host;
  proxy_set_header   X-Real-IP         $remote_addr;
}

configuration of the second nginx reverse proxy
server_name: ng2

location ^~ /kb/ {
    proxy_redirect off;
    proxy_pass http://ng1:80/;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 600;
    proxy_buffer_size 256k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
  }

expect the second nginx to access the kibana server as well as the first nginx.

now the error is: the browser accesses http://ng2/kb/ and the result url becomes http://ng2/app/kibana 404

.
Mar.21,2022

first of all, 404 is returned by the second nginx, because accessing http://ng2/app/kibana does not match the corresponding location . The guess is that accessing http://ng2/kb/ will be normal to kibana , kibana will jump, jump to / app/kibana , url will be redirected to http://ng2/app/kibana, so the above error occurs.

as long as there is a jump like location:/app/xxx , there is almost no way to set it. A better way is to create a new server to bind to the second nginx

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-1e821e9-45636.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-1e821e9-45636.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?