Introduction
This topic describes how to change the Linux addresses of Nginx, Tomcat, and Apache Web services on listening port ECS instances.
Background
- If you have already installed the Web server in the Linux, you can refer to the following documents to install and start the corresponding services:
- If you have already added security group rules to the security group to which the instance belongs, configure the HTTP protocol port to be allowed. For example, Nginx defaults to port 80 of TCP while Tomcat defaults to port 8080 of TCP.
Modify the listening port address of Nginx
- Remotely log on to the ECS instance of the Linux. For more information about how to log on to a Linux, seeconnect to a Linux instance by using a user name and password.
- Run the following command to check whether the port is properly listened on:
netstat -an | grep 80
The command output is as follows. If the command output is different from the information shown in the following figure, you must modify the listening port address. - Run the following command to find the
nginx.conf
file: The nginx path is typically/etc/nginx/nginx.conf
.find / -name nginx.conf
- Follow these steps to modify the nginx.conf file:
- Run the following command to edit the file:
vim /etc/nginx/nginx.conf
- Press the I key to enter the edit mode.
- Modify the following information in the
http
.server {
The modified information is similar to the following.
listen 80;
server_name localhost;server {
listen [$IP]:80;
server_name localhost;Note:[$IP] is the public IP address of the instance.
- Press the Esc key to exit the editing mode, and enter ": wq" to save and exit.
- Run the following command to edit the file:
- Restart the Nginx service.
Modify the Tomcat listening port address
You must modify the listening port in the server.xml file of Tomcat. Perform the following steps:
- Remotely log on to the ECS instance of the Linux.
- Run the following command to find the
/conf/server.xml
file. The path is generallyempty
.find / -name server.xml
- Modify the
server.xml
file.- Run the following command to edit the file:
vim /usr/local/tomcat/conf/server.xml
- Press the I key to enter the edit mode.
- Add Connector information to the address.
<Connector port="8080"
The command output is as follows: x.x.x.x indicates the public IP address of the instance.
protocol="HTTP/1.1"
address="[$IP]"
- Run the following command to edit the file:
- Restart the Tomcat service.
Modify the listening port of Apache
- Remotely log on to the ECS instance of the Linux.
- Run the following command to find the
nginx.conf
file: The path is generallyempty
.find / -name httpd
- Follow these steps to modify the
httpd.conf
file:- Run the following command to edit the file:
vim /etc/httpd/conf/httpd.conf
- Press the I key to enter the edit mode.
- Replace the information in the
Listen
section with the following to modify the listening port, save the configuration, and exit.Listen [$Port]
Note:[$Port] is the Port you want to use. The default Port is 80.
- Run the following command to edit the file:
- Run the following command to restart Apache.
service httpd restart
Application scope
- Elastic Compute Service