How to check port occupation situation when AnQiCMS background cannot be accessed on a Linux server?
As an experienced website operation expert, I know that AnQiCMS excels in providing efficient and customizable content management solutions.AnQiCMS leverages the high concurrency and simple, efficient architecture of the Go language, bringing great convenience to many small and medium-sized enterprises and content operation teams.However, even the most excellent system is bound to encounter some "little incidents" during operation, such as the backend suddenly becoming inaccessible, which often leaves operators in a panic.
Today, let's delve deeply into a common culprit for the unavailability of the AnQiCMS backend on a Linux server - port occupation, and also introduce how to systematically check and solve this problem.
Why would you first suspect port occupation when AnQiCMS background 'disconnected'?
Imagine that your AnQiCMS website's front-end access is normal, content updates are proceeding as scheduled, but when you try to log in to the back-end management interface, the browser displays "Unable to access this website" or "Connection rejected"。At this time, in addition to factors such as firewalls and network configurations, port occupation is often the primary focus of troubleshooting.
AnQiCMS as an independent application needs to listen on a specific port on the server to provide services. According to the default configuration of AnQiCMS, this port is usually8001If this port is occupied by another process on the server, or if the old process of AnQiCMS fails to close properly, causing a port conflict, then the new AnQiCMS service cannot start or respond to requests normally, resulting in the inability to access the backend.Due to AnQiCMS being developed in Go language, the service process usually runs in the form of a single executable file, port conflicts are a very common problem for such applications during deployment and maintenance.
How to check port usage on a Linux server?
In Linux systems, to troubleshoot port occupancy, we have a very handy 'detective tool' -lsofcommand.lsofThe full name is "List Open Files", it can list the files currently opened by the system, and network connections in Linux are also considered as files, so we can view which processes are using which ports through it.
To check if a specific port is occupied, you can enter the following command in the terminal:
lsof -i:<端口号>
For example, if your AnQiCMS is running by default on8001port, you will enter:
lsof -i:8001
After executing the command, the system will return information similar to the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
anqicms 7621 root 3u IPv4 70347 0t0 TCP *:8001 (LISTEN)
This output information reveals the key to the problem:
COMMAND: The process name using this port is, here isanqicms.PID: The unique identifier of the process, i.e., the process ID. In this example, it is7621.USER: The user running the process.FD: File descriptor.TYPE: File type.DEVICE: Device number.SIZE/OFF: File size or offset.NODE: Node number.NAME: Detailed information about the network connection.*:8001 (LISTEN)Indicates that the process is listening on all IP addresses.8001on the port.
IflsofThe command has output, andCOMMANDThe column does not display the AnQiCMS process you are currently expecting to run (such as a lingering old process, or other completely unrelated services), then congratulations, you have found the 'suspect' occupying the port. If there is no output, it means8001The port is idle, then the problem may be with other aspects, such as firewall configuration, AnQiCMS service not started or failed to start, etc.
Resolve port conflict: 'Evict' or 'Relocate'
After finding the process occupying the port, there are usually two solutions:
'Evict': Terminate the process occupying the portThis is the most direct solution. You can use
lsofthe output of the commandPID, usingkillcommand to forcibly terminate the process.kill -9 7621Here
7621which is abovelsofin the command outputanqicmsprocess.PID.kill -9Is sending a forced termination signal, ensuring the process is immediately closed.After terminating the process occupying the port, you can try to restart your AnQiCMS service.If it is due to port occupation caused by residual old processes, this usually solves the problem.“Moving”:Modify the listening port of AnQiCMSIf you find that the process occupying the port is an important system service, or if you want to run multiple AnQiCMS instances on a server, then changing the listening port of AnQiCMS is a more secure long-term solution. The running port of AnQiCMS is usually configured in the root directory of the project.
config.jsonIn the file (the specific location may vary depending on your deployment method, but it is common in the application main directory). You need to edit this file and findportThe configuration item should be changed to an unused port currently, for example8002/8003And. Modifyconfig.jsonAfter the file, save and restart the AnQiCMS service.At the same time, if your website uses Nginx or Apache and other reverse proxies, please be sure to synchronize the modification of the reverse proxy configuration, pointing the proxy target port to the new listening port of AnQiCMS, so that external access can be normally routed to AnQiCMS.
Troubleshooting is not just about ports: some additional thoughts
Although port occupation is a common problem, troubleshooting is a systematic process. If the port occupation issue is ruled out but the background is still inaccessible, there are still some other directions that can be quickly checked:
- firewall settingsCheck the firewall of the server (such as
firewalldorufwDoes it allow external access to the port AnQiCMS is listening on. If the port is blocked by a firewall, external connections will not be possible even if the service is running normally. - Web server configurationIf you used Nginx or Apache web servers as reverse proxies, please check if their configuration files are correctly pointing to the listening port of AnQiCMS and whether the web server itself is running normally.
- AnQiCMS service status: Did the AnQiCMS service really start? You can use
ps aux | grep anqicmsCommand to check if there are any processes related to AnQiCMS running. If not, you need to check the startup script or log files to find out the cause of the failure. - AnQiCMS log file:AnQiCMS usually generates runtime logs. Checking the log file (the specific location depends on your deployment) can help you find internal error information in the program, which is crucial for troubleshooting.
Troubleshooting website issues is like solving a detective case, requiring patience and meticulousness.Starting with the most common 'suspect' of port occupation, by combining system tools and the characteristics of AnQiCMS, you can efficiently locate and solve problems, ensuring the continuous stable operation of your AnQiCMS website.
Frequently Asked Questions (FAQ)
Q1: Why did the AnQiCMS backend suddenly become inaccessible?A1: AnQiCMS backend suddenly cannot be accessed, there are many common reasons. First of all, it may beport occupiedcausing the AnQiCMS service to fail to start or respond. Secondly, it may be due to the serverfirewall configurationissue, preventing external access to the AnQiCMS port. In addition,Web server (such as Nginx/Apache) reverse proxy configuration errorAnQiCMSService itself stopped or failed to start abnormallyEven low-level file permissions and database connection issues can cause the background to be inaccessible. Compatibility issues may also arise after system updates or configuration changes.
Q2: Besides port occupation, what are some common configuration errors that can prevent access to the AnQiCMS backend?A2: In addition to port occupation, there are several common configuration errors worth noting. The first isThe firewall has not opened the listening port for AnQiCMSThe external request cannot reach due to. The second isReverse proxy configuration error of web server (Nginx/Apache)For example, the proxy address or port is incorrect, or the necessary request header settings are missing. Third, if AnQiCMS is configuredIndependent background domain name(In系统设置However, if the domain name is not resolved correctly or the corresponding SSL certificate/reverse proxy is not configured on the web server, it will also cause the background to be inaccessible. Finally, if the database connection information (config.jsonOr if there is a change or incorrectness in the initial configuration, AnQiCMS will also fail to run properly.
**Q3: If I changed the port of AnQiCMS in `config.