As a senior AnQiCMS website operation staff, 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 to avoid using the default port for security reasons.Below, I will explain in detail how to operate.
Understand the default port and configuration mechanism of AnQiCMS
AnQiCMS is an efficient content management system developed based on the Go language. Its default running port is set to8001。AnQiCMS 的核心配置,包括端口设置,都集中在项目根目录下的 Englishconfig.jsonfile.Therefore, modifying the default running port of the AnQiCMS instance essentially involves editing this configuration file and ensuring that all related services (such as reverse proxy) are synchronized updated.
Locateconfig.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 it through Baota panel, your AnQiCMS may be located at/www/wwwroot/yourdomain.com/This path. If deployed through Docker, although the modification inside the container is direct,config.jsonit may be overwritten by the image update, but for the instance unpacked and run directly on the host machine,config.jsonStill located in the extracted directory.
Modifyconfig.jsonPort value in.
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. Change8001it to the new port number you want to use, for example8002Please ensure that you select a port on the current server that is not occupied by other services to avoid conflicts.
The modified example is as follows:
{
"app_name": "AnQiCMS",
"port": "8002",
// ... 其他配置项
}
Saveconfig.jsonfile.
Update the reverse proxy configuration
AnQiCMS usually cooperates with Nginx, Apache, and other web servers to provide services through reverse proxy.When 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 corresponding site's Nginx configuration file (for example, on Baota panel, it is usually located in)/www/server/nginx/conf/vhost/yourdomain.com.conf)。In the configuration file, you will find similar reverse proxy settings:
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;
}
Save Nginx configuration file and then reload Nginx configuration to make it effective. In the command line, you can runsudo nginx -s reloadorsystemctl reload nginxIn 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-related settings in the configuration file and update the target port to the new port.
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 for it to take effect, for examplesudo systemctl restart apache2.
Panel tools (such as 1Panel, aaPanel, Baota Docker application) port settings:
If you have deployed AnQiCMS through the Docker app store or container management feature of these panels, changing the port may require doing so through the graphical interface of the panel.Generally, when creating or managing AnQiCMS containers, there will be port mapping settings.You need to make sure that the internal port of the container (usually still 8001) is mapped to the new port you choose on the host machine (for example, 8002).Also, the reverse proxy setting of the panel should point to this new port on the host.Please refer to the official documentation of the panel you are using.
Restart AnQiCMS instance
After modifyingconfig.jsonAfter the reverse proxy configuration, you need to restart the AnQiCMS instance to make the new port settings take effect.
- Manually running 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, use the command line on Linux)
kill -9 PID,in the Windows Task Manager, end the process), then restart the AnQiCMS executable file. - Instances run by scripts or service managers:If you use
start.shScripts orsystemdTo manage AnQiCMS process for service manager, please execute the corresponding restart command, for example,./stop.shafter./start.shorsystemctl restart anqicms. - BaotaGo project deployment:In the "Website" -> "Go Project" of the Baota panel, find your AnQiCMS project, click Stop first, then click Start.
- Docker container:If the container is a Docker container, you may need to stop and restart the container, or rebuild the container (if port mapping is defined when the container is created).
Verify if the new port is effective
Complete the above steps, then open your browser and visit your website's domain.If everything goes well, the website should load normally.netstat -tunlp | grep 8002(Replace 8002 with your new port).
Common Questions (FAQ)
1. What if the website cannot be accessed after modifying the port?
Firstly, please check carefully.config.jsonFile inportIs the value correctly modified and saved.Next, confirm that your reverse proxy (Nginx/Apache, etc.) configuration has been updated and reloaded/restarted.netstat -tunlp | grep 您的新端口Check if the AnQiCMS instance has started successfully on the new port.If the AnQiCMS process is not listening on a new port, check the startup log for more error information.Also, make sure that the firewall has opened the port you have just set.
2. Why is it necessary toconfig.jsonHow to 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 itself.The role of reverse proxy is to forward external requests to this internal listening port.If the AnQiCMS program is not running on the port you expect, you will not be able to establish a connection with AnQiCMS even if the reverse proxy configuration is correct.Therefore, both must be modified and configured synchronously to ensure consistency of the internal and external ports.
3. How to 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.