How to solve the error 'Port is already in use' when deploying AnQiCMS?

Calendar 👁️ 72

As an experienced security CMS website operator, I know that technical details often determine whether the operation is smooth or not.Among them, 'Port occupied' is a very common initial problem when deploying applications like AnQiCMS that run based on a specific port.But please be assured that this is not a difficult problem to solve. Just understand the principle and follow the steps, and you can easily resolve it.

Understand port occupation error

When you try to start the AnQiCMS service, if the system prompts the error message "Port is already in use", this means that the port you specified or the port (usually 8001) used by AnQiCMS by default has been occupied by another program or service on the server.AnQiCMS as a Go language developed enterprise-level content management system needs to listen to a specific network port on the server so that users can access it through a web browser.Each network port can only be used exclusively by one process at a time.Therefore, when AnQiCMS tries to start and bind to a port that is already in use, a conflict occurs, causing the service to fail to start.

There are many reasons for this situation. It may be that you previously started an instance of AnQiCMS but did not close it properly, or there are other web services, database services, or even development tools running on the server that may be using the same port.

Identify conflicting ports and occupied processes

The first step in solving the problem is to find out which process is occupying the port you need. In a Linux server environment, we can easily complete this task using command-line tools.

You can uselsofEnter the command to view the port occupancy of a specified port. For example, if AnQiCMS uses the default port 8001, you can enter the following command in the terminal:

lsof -i:8001

Execute this command and the system will list all processes that are listening or using port 8001, including key data such as process ID (PID), process name, etc.With this information, you can clearly see which program caused the port conflict.

Terminate the occupying process

After identifying the process occupying the port, if you confirm that the process is not a critical system service or can be temporarily stopped, you can choose to terminate it to release the port.Please operate with caution, ensure that you do not kill important processes by mistake.

You can usekill -9Command to forcibly terminate the process. In particular,-9The option indicates forced termination, please replace the actual process ID (PID) obtained in the previous step in the command.{PID}:

kill -9 {PID}

For example, iflsof -i:8001The command to display the PID of the process occupying the port is 7621, then the termination command will bekill -9 7621. After terminating the process, you can use it againlsof -i:8001to verify if the port has been released.

Change the AnQiCMS running port

If you do not want to terminate the process occupying the port, or find that the port is always easily occupied by other services, then the most thorough solution is to change the running port of AnQiCMS itself.AnQiCMS allows specifying the running port by modifying its configuration file.

The AnQiCMS running port configuration is located in the root directory of the project.config.jsonIn the file. You need to use a text editor (such asvi,nanoOr open this file through the SFTP tool) find and modifyportThe value of the field. For example, if the current port is 8001, you can change it to a less occupied port, such as 8002, 8003, or any other unused port number.

{
  "name": "默认模板",
  "package": "default",
  "version": "1.0",
  "description": "系统默认模板",
  // ... 其他配置项
  "port": 8002, // 将此处的端口号修改为新的未占用端口
  // ... 其他配置项
}

Modify and saveconfig.jsonAfter the file, make sure you choose a port that is not likely to be occupied by other services in the current or future.

Update reverse proxy configuration (if used)

Many AnQiCMS deployments choose to use Nginx or Apache as a reverse proxy to forward external 80 or 443 port traffic to the actual port where AnQiCMS is running.If you use a reverse proxy, you must also update your reverse proxy configuration after changing the running port of AnQiCMS.

For example, using Nginx, you need to edit the Nginx site configuration file (usually located in)/etc/nginx/conf.d/or/etc/nginx/sites-available/), findproxy_passCommand, and update the port number to the new running port of AnQiCMS. For example:

location @AnqiCMS {
    proxy_pass http://127.0.0.1:8002; # 更新为AnQiCMS的新端口
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

After modifying the Nginx configuration, please be sure to reload or restart the Nginx service to make the changes take effect.For Apache users, similar modifications are also required to update the target URL of the reverse proxy.

Restart the AnQiCMS service

After completing the port modification or process occupation, you need to restart the AnQiCMS service.If you are starting manually, please execute the corresponding start command.If it is deployed in a visual tool like Baota panel, usually just click the "Start" or "Restart" button.When deploying via the command line, if you usedstart.shScript, can be executed:

./start.sh

After restarting, AnQiCMS should be able to bind smoothly to a new or released port and provide services normally.You can try to access your website in the browser to confirm that everything is normal.

Considerations for multi-site deployment

When you deploy multiple AnQiCMS sites on the same server, the port occupation problem will become more prominent.It is**practical**to allocate a unique port for each AnQiCMS instance in this case.Each instance should have its ownconfig.jsonFiles, and configure differentportValue. At the same time, the reverse proxy configuration of each site should point to the exclusive port of the corresponding AnQiCMS instance to ensure that traffic can be routed correctly.

Resolving the 'port is occupied' issue is a basic but important skill in AnQiCMS operations.By following the steps introduced in this article, I believe you can quickly locate and resolve this type of problem, ensuring the stable operation of your CMS website.


Frequently Asked Questions (FAQ)

1. What is a port? Why does AnQiCMS deployment require a port?

A port is a concept in computer networking that allows multiple applications or services on a single computer to share the same IP address.Each port has a unique numeric identifier (0-65535).AnQiCMS as a network service needs to listen to a specific port to receive requests from the user's browser.When a user enters a website address in the browser, it is actually sending a request to the server's IP address and the default HTTP (80) or HTTPS (443) port.The reverse proxy server will forward these requests to the internal port that AnQiCMS is actually listening on, thereby enabling service access.In simple terms, a port is the 'gateway' through which applications communicate over a network.

2. I modified the port in config., but the website still cannot be accessed, what could be the reason?

If you have changed the running port of AnQiCMS but the website still cannot be accessed, there may be several reasons:

  • Reverse proxy not updated: If you use Nginx or Apache and other reverse proxy, you also need to update the reverse proxy configuration accordinglyproxy_passor the port number of the target URL to matchconfig.jsonThe new port is consistent, and the reverse proxy service needs to be restarted.
  • AnQiCMS service has not been restarted: while modifyingconfig.jsonAfter that, you must restart the AnQiCMS service to make the new port configuration take effect.
  • Firewall blockingThe server's firewall may be blocking access to the new port. You need to check the firewall rules to ensure the new port is open.
  • The port is still occupied: Even if you change the port, the new port may be occupied by other services unexpectedly. You can uselsof -i:{新端口号}command to check again.

How to solve port occupation when deploying AnQiCMS in Docker environment?

In Docker environment, port occupation usually occurs when the host port is mapped to the container port.When you map a port of the host machine (for example, 8001) to the port listened to by AnQiCMS inside the container (usually also 8001), an error will occur if the 8001 port on the host is already occupied.There are usually two solutions:

  • Change the host mapping portRun Docker commands ordocker-composeIn the file, modify the host port mapping and select an unused host port. For example, to map8001:8001changed to8002:8001means to map the host's 8002 port to the container's 8001 port.
  • Change the listening port inside the container for AnQiCMSThis usually involves building a custom Docker image, or modifying the AnQiCMS inside the container by passing environment variables or mounting configuration files at startup.config.jsonin the fileportConfigure. Then, you can map any unused port of the host to the new listening port inside the AnQiCMS container.No matter which way, if you use a reverse proxy, please remember to synchronize the configuration of the reverse proxy.

Related articles

How to test and run AnQiCMS program under Windows environment?

As an experienced CMS website operator, I am well aware of the importance of efficiently testing and running CMS programs in a local environment, especially on Windows systems, for content creation and optimization processes.AnQiCMS is a system developed based on the Go language, with its lightweight and efficient characteristics, the deployment and testing in the Windows environment are also relatively convenient.Below, I will explain in detail how to test and run the AnQiCMS program in the Windows environment

2025-11-06

How to install and manage multiple AnQiCMS sites on the same server?

AnQiCMS is an efficient and flexible content management system, its multi-site management function is designed to meet the needs of small and medium-sized enterprises, self-media operators, and users with multiple brands or content branches.As an experienced website operations manager, I am well aware of the importance of efficiently managing multiple sites on the same server, which not only saves server resources but also simplifies daily maintenance work.Below, I will elaborate on how to install and manage multiple AnQiCMS sites on the same server.

2025-11-06

How to configure Nginx rewrite rules when installing AnQiCMS on the Baota panel?

The AnQiCMS content management system is increasingly becoming the preferred tool for small and medium-sized enterprises and content operation teams due to its efficient features based on the Go language and its SEO-friendly design concept.As an old veteran who has been deeply involved in website operation for many years, I fully understand the importance of high-quality content and excellent user experience, and the elegant URL structure is the key to improving these experiences.The built-in pseudo-static feature of AnQiCMS is exactly what is needed to achieve this goal.

2025-11-06

How to use Baota panel to install AnQiCMS on a Linux server?

As an experienced security CMS website operator, I know that the deployment of the content management system is the foundation of successful operation.AnQiCMS with its high performance, security, and ease of use based on the Go language, has become the ideal choice for many small and medium-sized enterprises and content operation teams.Install AnQiCMS on a Linux server using the Baota panel can greatly simplify the deployment process, allowing you to quickly get involved in content creation and operation.This article will introduce you in detail how to easily install and configure AnQiCMS on a Linux server using the Docker feature of Baota panel

2025-11-06

What are the core function modules provided by the AnQiCMS backend?

As an experienced website operator, I have a deep understanding and practical experience of the powerful functions of AnQiCMS.This is an enterprise-level content management system developed based on the Go language, which provides a comprehensive solution for small and medium-sized enterprises, self-media operators, and multi-site management users with its efficient, customizable, and scalable features.It not only simplifies the content management process, but also helps the website stand out in the highly competitive digital environment through a series of refined functions.The core functional module of AnQiCMS backend, aiming to cover all aspects of website operation, from content creation to publishing

2025-11-06

How to set global functions, content, and contact information in the AnQiCMS background?

As an experienced CMS website operation person in the security industry, I am fully aware that the background settings are crucial for the overall operation efficiency and user experience of the website.Efficiently manage global functions, content processing, and external communication methods, which is the foundation to ensure the stable operation of the website, high-quality presentation of content, and effective engagement with users.Below, I will give you a detailed explanation of how to perform these key settings in the AnQiCMS backend.### Website Global Function Settings Global function settings are the 'master switch' of the AnQiCMS website, affecting every aspect of the site, from brand identity to access status, to multilingual support

2025-11-06

How to manage and publish articles, products, and other document content in AnQiCMS?

As a senior CMS website operation personnel, I know that content is the lifeline of the website.AnQiCMS is a content management system designed specifically for small and medium-sized enterprises, self-media, and multi-site managers, with its core advantages lying in providing efficient, flexible, and comprehensive content creation, publishing, and optimization tools.By fine-tuning content management, we can not only attract new users, but also maintain existing user groups by continuously providing high-quality information.I will elaborate on how to effectively manage and publish various types of document content in AnQiCMS, such as articles and product information

2025-11-06

How to optimize content organization in AnQiCMS's document classification and tag function?

As an experienced CMS website operation personnel of AnQi, I know the core status of content organization in website operation.A website with a clear structure and easy retrieval not only improves user experience, but is also the foundation for search engine optimization.AnQiCMS (AnQiCMS) provides an efficient and flexible solution for content organization through its powerful document classification and tagging features.### How to optimize content organization in AnQiCMS: The strategic application of categorization and tagging Effective content organization in a content management system is crucial for improving website usability and search engine visibility

2025-11-06