As an experienced CMS website operation personnel for information security, I am well aware that the stable operation of the website is of great importance.Port conflict is often encountered during the initial deployment or multi-site management, which will cause the AnQiCMS service to fail to start or be inaccessible.Understand how to accurately diagnose and resolve such issues is crucial for ensuring your website runs smoothly.
Port conflict common scenarios
AnQiCMS uses by default8001Port.When another service (such as other Web applications, database services, test services, etc.) on the server occupies the port required by AnQiCMS, or when you try to deploy multiple AnQiCMS instances on the same server without assigning different ports for them, a port conflict will occur.This situation usually manifests as the AnQiCMS service failing to start, or even if it displays 'Start successful', the website cannot be accessed through a web browser.
Steps to identify and resolve AnQiCMS port conflict
To accurately locate and resolve the port conflict of the AnQiCMS process, we need to rely on the Linux system under.lsofa command.lsof(list open files)is a powerful tool that can list information about the currently open files in the system, including network connections.
Confirm potential conflicting ports
Firstly, you need to specify the port that AnQiCMS is expected to use. In most cases, the default port is8001. If you have manually modified the AnQiCMS configuration file (for exampleconfig.jsonTo specify other ports, or if you have configured a specific port when deploying through Baota panel, 1Panel, or similar tools, please make sure to use the actual port number for the query.
ExecutelsofQuery command port occupancy situation
In the SSH terminal, use the following command to check the occupancy of a specific port:
lsof -i:{端口号}
For example, to check the default:8001Port, you will enter:
lsof -i:8001
This command means:
lsof: List the opened files.-i: Filter network files (internet files).:{端口号}: Specify the port number to be queried.
Analyze command output results
After the command is executed, if the port is being used, you will see output similar to the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
anqicms 7621 root 3u IPv4 70347 0t0 TCP *:8001 (LISTEN)
Key information in the output includes:
COMMAND: The program name currently using this port. In AnQiCMS scenarios, this will usually display asanqicmsor other custom service names.PID: 占用该端口的进程ID(Process ID)。This is the core information you need for your next operation.USER: 运行该进程的用户。NAME: Displayed the port number and connection status (for example*:8001 (LISTEN)indicating that port 8001 is in listening state).
If the output is empty, it means that the port is currently not occupied by any process, and you can safely allow AnQiCMS to use the port.
Resolve port conflict
When you confirm the process that occupies the port required by AnQiCMS, there are several ways to resolve conflicts:
Terminate the conflicting processIf the process occupying the port is not AnQiCMS, and the process is not a core system service, you can choose to terminate it. Use
kill -9 {PID}Command forces the termination of a process. For example, if the PID is7621, the command will be:kill -9 7621Note:
kill -9This is a mandatory termination command, please use it with caution, ensure you understand the role of the terminated process, and avoid mistakenly killing important system services. If you are unsure, please seek professional assistance.Change the listening port of AnQiCMS: This is the recommended method, especially when the port is occupied by another important service. You can modify the AnQiCMS configuration file (usually
config.json)to specify a new, unused port. For example, to"port": 8001Change to"port": 8002.If you deploy through Docker, Baota Go project, and other methods, you need to reconfigure the listening port of AnQiCMS on the deployment interface and ensure that the corresponding reverse proxy is also updated to the new port.change the listening port of another serviceIf AnQiCMS must use a specific port (such as for SEO or URL consistency), and another service is using that port, and that service allows port configuration, you can try to change the port of that service.
Verify the solution
After taking the above measures, restart your AnQiCMS service. Then, use it againlsof -i:{端口号}Confirm that AnQiCMS has successfully listened on the target port, and try to access your website through the browser to ensure everything is normal.
Common Questions and Answers (FAQ)
1.config.jsonWhere is the file? How do I modify the listening port of AnQiCMS?
config.jsonis the core configuration file of AnQiCMS, usually located at the root of the AnQiCMS installation directory. You can log in to the server using SSH,cd /path/to/anqicmsEnter your AnQiCMS installation directory, then usevi config.jsonornano config.jsontext editor to modify. Find"port"field, and change its value to an unused port number (for example8002Then save and exit. AnQiCMS needs to be restarted for the new configuration to take effect.
2. How can I run multiple AnQiCMS instances on the same server without port conflicts?To run multiple AnQiCMS instances on a single server, each instance must listen on a unique port. You need to set a unique port for each AnQiCMS instance:
- Assign an independent installation directoryDeploy AnQiCMS code to a different folder.
- Modify
config.jsonFor each instance ofconfig.jsonin the file, will"port"Field modified to a different, unused port number (for example, the first instance uses8001, the second uses8002, and so on). - Configure Reverse ProxyIf you access these AnQiCMS instances via domain name, you need to configure the reverse proxy of the web server (such as Nginx or Apache) for each instance, forwarding different domain names or subdirectory requests to the different ports that the corresponding AnQiCMS instance is listening on.
3. What are the consequences if I mistakenly kill the wrong process?
kill -9The command will forcibly terminate a process without giving it a chance to clean up or save data.If the service mistakenly killed is an important system service (such as SSH service, database service, or the web server itself), it may cause abnormal system functions, data loss, or even make the server unremotely connectable.kill -9Please make sure to check carefully before that.COMMANDandPIDEnsure that you are terminating the correct and harmless process. If you are not sure, it is best to choose to modify the port of AnQiCMS or seek help from the system administrator.