The secondary directory of the Nginx proxy server accesses any file the same.

problem description

in development, there is a server that needs a proxy http://192.168.6.103:9763, and we want to be proxied by a directory http://192.168.6.103:9763/static/. Instead of the agent http://192.168.6.103:9763, the problem after configuration is that you can access the secondary directory static, of the agent"s server, but the js,css, image responses for all requests are all the same. All are home pages

the environmental background of the problems and what methods you have tried

after trying a lot of location configurations, access to css,js, images is still the same.

related codes

/ / Please paste the code text below (do not replace the code with pictures)
below is set, access to static files is the same as any file.

worker_processes 1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
  upstream tomcat_01 {
    server 192.168.6.103:9763 max_fails=3 fail_timeout=600;
  }

  upstream tomcat_02 {
    server 192.168.6.106:9763 max_fails=3 fail_timeout=600;
  }

  upstream default {
    server 192.168.6.106:9763 max_fails=3 fail_timeout=600;
  }

  server {
      listen 81;
      server_name  localhost;
      set $group default; 
      if ($remote_addr ~ "192.168.20.52") {
        set $group tomcat_02;
      }

    location /{
       proxy_pass http://$group/static/;
       proxy_set_header   Host             $host;
       proxy_set_header   X-Real-IP        $remote_addr;
       proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      index  index.html index.htm;
   }
  
  location ~* \.(png|gif|css|js)$ {
     alias http://$group/static;
  } 
}
}

Home page after proxy
clipboard.png

clipboard.png

clipboard.png

what result do you expect? What is the error message actually seen?

how can I get the server behind the proxy to access static files normally instead of having all request responses the same? Could you tell me how to solve it? thank you!

Mar.28,2021
Menu