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
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
Use the
findcommand to locate the Nginx configuration filenginx.conf.NoteThe default path for the Nginx configuration file is typically
/etc/nginx/nginx.conf.sudo find / -name nginx.confModify the
listenfield in theserverblock of thenginx.confconfiguration file. Then, restart Nginx.Run the following command to check if the new port is listening. In this example, port 88 is used.
netstat -an | grep 88If the output contains LISTEN, port 88 is listening.
Modify default Tomcat port
Use the
findcommand to find the Tomcat configuration fileserver.xml.NoteThe Tomcat configuration file is typically located at
/usr/local/tomcat/conf/server.xmlor/etc/tomcat/server.xml.sudo find / -name server.xmlModify the
portattribute of the<Connector>tag in the Tomcat configuration fileserver.xml. After the modification is complete, restart Tomcat.Run the following command to check if the new port is listening. In this example, port 8081 is used.
netstat -an | grep 8081If the output contains LISTEN, port 8081 is listening.
Modify default Apache port
Use the
findcommand to locate the Apache configuration filehttpd.conf.NoteThe default path for the Apache configuration file is typically
/etc/httpd/conf/httpd.conf.sudo find / -name httpd.confIn the Apache configuration file
httpd.conf, modify theListenattribute. After the modification is complete, restart Apache.Run the following command to check if the new port is listening. In this example, port 88 is used.
netstat -an | grep 88If the output contains LISTEN, port 88 is listening.