All Products
Search
Document Center

:Modify listening ports for Nginx, Tomcat, and Apache on a Linux ECS instance

Last Updated:Apr 15, 2026

This topic explains how to change the listening port for Nginx, Tomcat, or Apache on a Linux ECS instance.

Prerequisites

You have one of the following services installed on your ECS instance:

  • Nginx

  • Tomcat

  • Apache

Important
  • If the modified port is in use, the service will fail to start. You can run the netstat -an | grep <port_number> command to determine if the port is in use.

  • If you want to access the service over the Internet after you modify the port, add an inbound rule to the security group. For more information, see Scenario 1: Deploy a website on an ECS instance.

Modify Nginx port

  1. Use the find command to locate the Nginx configuration file nginx.conf.

    Note

    The default path for the Nginx configuration file is typically /etc/nginx/nginx.conf.

    sudo find / -name nginx.conf 
  2. Modify the listen field in the server block of the nginx.conf configuration file. Then, restart Nginx.

  3. Run the following command to check if the new port is listening. In this example, port 88 is used.

    netstat -an | grep 88

    If the output contains LISTEN, port 88 is listening.

Modify default Tomcat port

  1. Use the find command to find the Tomcat configuration file server.xml.

    Note

    The Tomcat configuration file is typically located at /usr/local/tomcat/conf/server.xml or /etc/tomcat/server.xml.

    sudo find / -name server.xml 
  2. Modify the port attribute of the <Connector> tag in the Tomcat configuration file server.xml. After the modification is complete, restart Tomcat.

  3. Run the following command to check if the new port is listening. In this example, port 8081 is used.

    netstat -an | grep 8081

    If the output contains LISTEN, port 8081 is listening.

Modify default Apache port

  1. Use the find command to locate the Apache configuration file httpd.conf.

    Note

    The default path for the Apache configuration file is typically /etc/httpd/conf/httpd.conf.

    sudo find / -name httpd.conf
  2. In the Apache configuration file httpd.conf, modify the Listen attribute. After the modification is complete, restart Apache.

  3. Run the following command to check if the new port is listening. In this example, port 88 is used.

    netstat -an | grep 88

    If the output contains LISTEN, port 88 is listening.