As an experienced AnQiCMS (AnQiCMS) website operations personnel, I know that every detail of the system configuration is related to the stability and security of the website.Modifying the default port of AnQiCMS instances is a common requirement in website deployment and security optimization, especially when you need to run multiple AnQiCMS instances on the same server or avoid using the default port for security reasons.Below, I will explain to you in detail how to operate.

Understand the default port and configuration mechanism of AnQiCMS

AnQiCMS is a high-efficiency content management system developed based on the Go language. Its default running port is set to8001The core configuration of AnQiCMS, including port settings, is all located in the root directory of the project.config.jsonIn the file. Therefore, modifying the default runtime port of the AnQiCMS instance is essentially editing this configuration file and ensuring that all related services (such as reverse proxies) are synchronized updated.

Positioningconfig.jsonFile

To modify the default port of the AnQiCMS instance, you first need to find the root directory of the AnQiCMS project deployment. In this directory, you will find a file namedconfig.jsonThe file. This file contains the key runtime configuration of the AnQiCMS instance.

For example, if you deployed through Baota panel, your AnQiCMS may be located at/www/wwwroot/yourdomain.com/This path. Although the modification of the container inside is directly deployed through Docker,config.jsonit may be overwritten by the image update, but for the instance that is unpacked directly on the host machine,config.jsonIt is still in the directory after unpacking.

modifyconfig.jsonof the port value

Findconfig.jsonAfter the file, open it with a text editor (such as Vim, Nano, or Baota's file editor). You will see a JSON structure similar to the following:

{
  "app_name": "AnQiCMS",
  "port": "8001",
  // ... 其他配置项
}

Here,you need to find"port": "8001"this line and8001change it to the new port number you want to use,for example8002Make sure to choose a port that is not occupied by other services on the current server to avoid conflicts.

Here is an example of the modified version:

{
  "app_name": "AnQiCMS",
  "port": "8002",
  // ... 其他配置项
}

Saveconfig.jsonfile.

Update the reverse proxy configuration

AnQiCMS usually works with Nginx, Apache, and other web servers to provide services through reverse proxy.After you modify the internal running port of the AnQiCMS instance, be sure to synchronize the configuration of the reverse proxy, otherwise your website will not be accessible.

Nginx reverse proxy configuration example:

If you are using Nginx, please find the Nginx configuration file for the corresponding site (for example, in Baota panel, it is usually located in/www/server/nginx/conf/vhost/yourdomain.com.conf). You can find similar reverse proxy settings in the configuration file:

location @AnqiCMS {
    proxy_pass http://127.0.0.1:8001; # 这里需要修改为新端口
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

toproxy_pass http://127.0.0.1:8001;of8001Modify it toconfig.jsonthe new port number you set in8002.

The following is an example after modification:

location @AnqiCMS {
    proxy_pass http://127.0.0.1:8002; # 修改为新端口
    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 saving the Nginx configuration file, you need to reload the Nginx configuration for it to take effect. You can run it in the command line.sudo nginx -s reloadorsystemctl reload nginx. In the Baota panel, you can click "Reload Configuration" on the Nginx service management page.

Apache Reverse Proxy Configuration Example:

If you use Apache, you also need to update the corresponding virtual host configuration file.Find the reverse proxy settings in the configuration file, update the target port to the new port. For example:

ProxyPass        "/" "http://127.0.0.1:8001/" # 这里需要修改为新端口
ProxyPassReverse "/" "http://127.0.0.1:8001/" # 这里需要修改为新端口

Change to:

ProxyPass        "/" "http://127.0.0.1:8002/" # 修改为新端口
ProxyPassReverse "/" "http://127.0.0.1:8002/" # 修改为新端口

After saving the Apache configuration file, you need to restart the Apache service to make it effective, for examplesudo systemctl restart apache2.

Panel tools (such as 1Panel, aaPanel, Baota Docker application) port settings:

If you are deploying AnQiCMS through this panel's Docker app store or container management feature, you may need to modify the port in the panel's graphical interface.Generally, there will be port mapping settings when creating or managing AnQiCMS containers.You need to make sure that the container's internal port (usually still 8001) is mapped to the new port you choose on the host machine (for example, 8002).At the same time, the reverse proxy settings of the panel should also point to this new port of the host.Please refer to the official documentation of the panel you are using.

Restart AnQiCMS instance

After modifyingconfig.jsonAfter configuring the reverse proxy, you need to restart the AnQiCMS instance to make the new port settings take effect.

  • Manually run the instance:If AnQiCMS is run directly via the command line or by double-clicking the executable file, you need to stop the currently running AnQiCMS process first (for example, using Linux onkill -9 PIDIn the Windows Task Manager, end the process), then restart the AnQiCMS executable file.
  • Instances run through scripts or service managers:If you usestart.shScript orsystemdto manage the AnQiCMS process using a service manager, please execute the corresponding restart command, for example./stop.shafter./start.shor,systemctl restart anqicms.
  • BaotaGo project deployment:In the Baota panel, find your AnQiCMS project under “Website” -> “Go Project”, click stop first and then click start.
  • Docker container:If it is a Docker container, you may need to stop and restart the container, or rebuild the container (if the port mapping is defined when the container is created).

Check if the new port is effective

After completing the above steps, open your browser and visit your website's domain.If everything goes well, the website should load normally. You can also check if the new port is being listened to using the command line tool, for example, on Linux.netstat -tunlp | grep 8002(Replace 8002 with your new port).

Frequently Asked Questions (FAQ)

What should I do if the website cannot be accessed after changing the port?

First, please check carefullyconfig.jsonIn the fileportDoes the value have been correctly modified and saved? Secondly, confirm that your reverse proxy (Nginx/Apache, etc.) configuration has been synchronized and reloaded/restarted.Finally, usenetstat -tunlp | grep 您的新端口Command to check if the AnQiCMS instance has successfully started on the new port.If the AnQiCMS process is not listening on a new port, check the startup log for more error information.At the same time, also confirm that the firewall has opened the port you have newly set.

Why do I need to use it?config.jsonShould modify the port instead of directly modifying it in the reverse proxy?

config.jsonThe port defined is the port that the AnQiCMS program listens to.The reverse proxy forwards external requests to this internal listening port.If the AnQiCMS program is not running on the port you expect, even if the reverse proxy configuration is correct, you will not be able to establish a connection with AnQiCMS.Therefore, both must be modified and configured synchronously to ensure consistency between internal and external ports.

3. How can I know which ports are available?

On a Linux server, you can usenetstat -tunlpCommand to view all currently listening ports. Avoid using ports occupied by other services, as well as some commonly used system reserved ports (such as 21, 22, 80, 443, etc.), and usually choose non-privileged ports between 1024 and 65535.If you are testing locally, you can also view it through some network tools or the port checking function of the operating system.