How to Change Default Port of Tomcat Server?

Before we actually move onto the main step of seeing how we can change the default port of our tomcat server, let us first go into a little more depth and see what actually this tomcat server is and what are some applications where it is mostly used.

As mentioned before, the Apache Tomcat server is an open-source web server that acts as a servlet container for the implementation of several large-scale Java enterprise specifications such as Java Servlet, Java Server Pages, Java Expression Language, and Java WebSocket technologies. Servlet containers are part of the webserver and can be described as more or less an application server that provides the programming model everything else that it needs – the opening of sockets, managing some components, handling API calls, and so on. The Apache Tomcat server is one of the most widely used servers out there and has been powering up several large-scale enterprise applications. In addition to this, since it is opensource and falls under the Apache License, it includes a large developer list and several forums where people are always providing their input and offering aid to one another.

Without further ado, let us finally move on to the main topic of our article.

Changing Default Port

By default, the Tomcat server runs on the 8080 Port number. However, if there comes a need to change this, then it can be done easily by sticking to the following steps:

1. Locating the Server.xml File in Tomcat Directory
First, we need to find out where exactly did we install the tomcat server. In Windows, go to your C directory, then into the Program files directory, look for any directory with the names Tomcat, Apache Software Foundation, or Apache. If you find any of these, then open them and then search for the conf directory.

After locating this, open it, and there will be a file called server.xml. Open this with any file editor that you like.

In Linux, you can easily find the home directory of tomcat by searching in the search window. After finding it, open it and then go inside the conf directory and open the server.xml file.

After opening the xml file, you will see something similar at the beginning of it:

2. Finding the Connector Tag
After opening the server.xml file, try to find a line starting with the Connector tag. Depending on your version of tomcat, these might be either of the two below:

First Version:

<Connector port="8080" maxHttpHeaderSize="8192"
   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
   enableLookups="false" redirectPort="8443" acceptCount="100"
  connectionTimeout="20000" disableUploadTimeout="true" />

Second Version:

<!-- A "Connector" represents an endpoint by which requests are received
    and responses are returned. Documentation at:
    HTTP Connector: /docs/config/http.html
    AJP Connector: /docs/config/ajp.html
    Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->

<Connector port="8080" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />

3. Changing the Port Number
As you have noticed, the Connector tag in each of the two versions above has a port property attached to it and this has the default port number assigned to it. To make your Tomcat server run on a different port, simply replace this port with the port number you want the tomcat server to run on. For example, I want my tomcat server to run on the 8090 port, then the change I would make to the Connector tag would be:

<Connector port="8090" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />

As can be seen in the above example, I simply replaced the 8080 number which was placed in the Port property with my Port, 8090.

4. Restarting Tomcat
After changing the Port of the Tomcat server, save the server.xml file. If your Tomcat server is currently running, stop it, restart and start it again. If it isn’t running, simply restart and then start it. Now, when you run your Tomcat server, it will be running on the port that you specified. In my case, it would be the 8090 port.

Conclusion

The Tomcat server is one of the most widely used web servers out there and has become immensely popular in the community. It has some well-defined commands and is easily configurable as seen by the steps shown in the article about changing its default port. All in all, it’s a tool worth putting your time.



from Linux Hint https://ift.tt/3m3LAPa

Post a Comment

0 Comments