AnQiCMS as an efficient and flexible content management system, is favored by many users for its lightweight characteristics in the Go language and ease of deployment.However, you may encounter a little detour - a "port is already in use" error prompt during the installation or startup of AnQiCMS.Don't worry, this is usually a common and easy problem to solve.As an experienced website operations expert, I will deeply analyze this issue for you and provide clear and practical solutions to help you smoothly set up the AnQiCMS site.

Understand the meaning of "Port is already in use"

To solve a problem, first you need to understand its essence.“Port” is like a “dedicated channel number” for an application on a server to provide services. Each application can only use a unique port to provide services at the same time.AnQiCMS on startup will attempt to listen on port 8001 by default.If another application on the server (whether it is another Web service, database, or other program) is using the 8001 port, then AnQiCMS cannot start successfully, and the system will prompt "Port is in use".This is like two applications trying to use the same phone number at the same time, and of course, conflicts will occur naturally.

The reasons for this situation are various: it may be that the AnQiCMS instance you started earlier did not close normally, leaving a 'zombie process'; it may also be that other services are installed on the server and they happen to use the same port by default; or you may be deploying multiple AnQiCMS sites on the same server without assigning them different ports.

Solution one: Find and terminate the process occupying the port

If the port is occupied by a process you do not need or have forgotten, the most direct method is to find it and terminate it.

ForLinux serverUser, you can uselsofcommand to view the usage of a specific port. For example, to check port 8001:

lsof -i:8001

After executing this command, the system will list the process information occupying this port. The most critical one is 'PID' (Process ID), which is equivalent to the 'ID card number' of this application.

After finding the PID of the process occupying the port, you can usekill -9the command to force quit the process. For example, if the PID is 7621:

kill -9 7621

before executingkill -9Please be cautious when issuing commands, ensure that you terminate is the correct and non-critical process, to avoid affecting the normal operation of other critical services on the server.Terminate the process and try to start AnQiCMS again, it usually starts smoothly.

ForWindows usersAlthough the operation is slightly different, the principle is similar. You can open the "Task Manager" (by pressingCtrl+Shift+EscShortcut key, or right-click on the taskbar and select it), switch to the "Details" or "Processes" tab.Then, you can try to find the relevant process through the 'PID' column (if it is not displayed, you can right-click on the column title to select Add) or directly judge and end it according to the process name.netstat -ano | findstr :8001Find the PID that is using port 8001, and then go to the Task Manager to end the process corresponding to the PID.

Solution two: modify the listening port of AnQiCMS.

If the 8001 port is occupied by an important application that cannot be easily closed, or if you plan to run multiple AnQiCMS instances on the same server, it is a wiser choice to modify the listening port of AnQiCMS itself.AnQiCMS designed with high flexibility, allowing you to easily adjust its listening port.

The port configuration of AnQiCMS is stored in the installation directory.config.jsonfile. You only need to open this file with a text editor (such as Vim, Nano, Notepad++等) and findportfield, and set its default value8001Modify to an unused port number, for example8002/8003Even other ports you choose yourself, and that are not reserved by the system (it is recommended to choose a port between 1024 and 49151).

{
  "port": 8002, // 将这里的端口号修改为您想要的值
  "database": {
    // ... 其他数据库配置 ...
  },
  // ... 其他配置 ...
}

Saveconfig.jsonAfter the file, restart AnQiCMS.

Special reminder: If you have used Nginx or Apache and other web servers for reverse proxy,Then after modifying the listening port of AnQiCMS, you also need to synchronize the reverse proxy configuration of the web server. Change the port number in the proxy target URL to8001update to the one you haveconfig.jsonSet the new port. For example, in the Nginx configuration,proxy_pass http://127.0.0.1:8001;needs to be modified toproxy_pass http://127.0.0.1:8002;This ensures that external requests can correctly access your AnQiCMS service through reverse proxy.

If you deploy AnQiCMS via Docker, 1Panel, aaPanel, or similar platforms, these platforms usually provide a graphical interface for managing port mapping and reverse proxy.In these environments, you may need to modify the port exposed by the AnQiCMS container in the container configuration and update the corresponding website's reverse proxy settings.docker-1panel.md/docker-bt.mdThere is a detailed explanation of this, you can refer to it.

Deployment of multi-site**

AnQiCMS natively supports multi-site management, which is very convenient for users who want to operate multiple websites on a single server. The practice to avoid the error "Port already in use" during multi-site deployment is:

  1. Allocate an independent port for each AnQiCMS instance:Ensure each AnQiCMS is deployed manually or via Docker:config.jsonofportThe settings are unique.
  2. Use reverse proxy for unified management:Configure an independent domain and reverse proxy rule for each AnQiCMS instance through Nginx or Apache, and forward requests from different domains to AnQiCMS instances on different ports.Thus, when users access, they only need to use the domain name, without concerning about the specific port number.


Common Questions (FAQ)

Q1: Why do I frequently encounter port occupation issues?

A1:

Q2: After modifying the port of AnQiCMS, do you need to modify other configurations besides reverse proxy?

A2:If you are justconfig.json

Q3: I don't know which port to choose to avoid conflicts, do you have any recommended port range?

A3:Generally, port numbers can be divided into three categories:

  • 知名端口(Well-known Ports):English0 to 1023, usually occupied by system services and common protocols, such as HTTP (80), HTTPS (443), SSH (22), etc., and should be avoided as much as possible.
  • Registration Ports (Registered Ports):1024 to 49151, these ports can be used by user applications or services, and the default 8001 of AnQiCMS falls within this range.You can choose a relatively late and less commonly used port within this range, such as 8080, 8888, 9000, or even a four-digit or five-digit random number.
  • Dynamic/Private Ports (Dynamic/Private Ports):49152 to 65535, usually used for client applications to establish temporary connections.

To avoid conflicts, it is recommended that you choose an unused port within the registration port range (1024-49151). Before selecting a new port, you can uselsof -i:端口号(Linux)ornetstat -ano | findstr :端口号(Windows)to check if the port is occupied, make sure it's all secure.