I have installed Tomcat server on my server PC with IP 127.0.0.1 One application is running on the server. Let address of the application is: 127.0.0.1:8080/first-project Now if I want to run another application on the same server, address will be: 127.0.0.1:8080/second-project
I want multiple application with multiple addresses like 127.0.0.1, 127.0.0.2
a) Is this possible to have multiple address on single PC?
b) What is the best practice for running multiple server on same server and how to do that?
- With different IP address (127.0.0.1, 127.0.0.2)
- With same IP address but different port (127.0.0.1:8080, 127.0.0.1:8081)
- With same IP different path (127.0.0.1/first, 127.0.0.1/second)
Any resource link will be helpful. Thanks in advance.
CodePudding user response:
Not an expert of networking, but what I would suggest to you is the following
- You can have many application running on the same server, in the same
Tomcat Server
but you have to set differents ports. Example :http://localhost:8080/
orhttp://localhost:8082/
orhttp://localhost:8084/
- You can run your applications in Docker. Then you will be able to run your application in an isolated container with its own
IP address
. WithDocker
, you can usedocker-compose
to run many containers - You can run your applications in differents virtual machines. You will be able to configure each virtual machines with their own
IP address
to interact with yourhost
or from external location. - You can, have multiple
IP address
on a single network card
CodePudding user response:
You cannot have several ip addresses on one machine, that's what ports are for. You assign a port to an application, in application.properties
, eg. server.port = 8081
.
Now, paths are assigned by Controllers
and their methods, eg.
@Controller("/first")
publc class FirstController {
@GetMapping("/hello")
public String hello() {
return "Hello world!";
}
}
edit
I think you're talking about the context path, which you can specify also in application.properties
like so: server.servlet.context-path = /mycontext
.