Nginx accesses different native tomcat through url

how to access tomcat, of different ports open on this machine through nginx
for example, there are six tomcat on this machine

is
tomcat1 8080
tomcat2 8081
tomcat3 8082
tomcat4 8083
tomcat5 8084
tomcat6 8085

, respectively.

then the server newly deploys the nginx service, Let all services access
through 80% of nginx, such as http://192.168.102.100/tomcat1 access items under tomcat1
http://192.168.102.100/tomcat2 access items under tomcat2
http://192.168.102.100/tomcat3 visits items under tomcat3
http://192.168.102.100/tomcat4 visits items under tomcat4

Mar.04,2021

reverse proxy through the configuration file, add the following location, to nginx.conf and change localhost to the desired ip.

server {
    location /tomcat1 {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8081;
    }
    location /tomcat2 {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8082;
    }
    location /tomcat3 {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8083;
    }
}

/ back up the default configuration file of nginx and change it.
server {
-sharp this is the port 80 you want to proxy to
listen 80;
-sharp this is the domain name
server_name http://localhost;

.

root html;

access_log logs/nginx.access.log main;

-sharp then here are several tomcat

-sharp default requests
location / {
index index.php index.html index.htm;
}
location / tomcat1 {

        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8081;
    }
    location /tomcat2 {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8082;
    }
    location /tomcat3 {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://localhost:8083;
    }
    -sharp
}

Why the result of my visit is 404; it is possible to access tomcat directly

Menu