As an experienced CMS website operation personnel, I know that it is crucial to manage multiple websites flexibly and efficiently in a continuously developing digital environment.The AnQi CMS provides a solid foundation for us with its high concurrency features in Go language and multi-site management capabilities.However, when we want to deploy multiple independent AnQiCMS instances on the same server (instead of using the multi-site feature of a single instance), a core technical challenge is how to effectively avoid port conflicts.
This article will detail how to install and run multiple AnQiCMS instances on the same server in a non-Docker environment, and ensure that they do not interfere with each other due to port occupation.
Understanding the essence of port conflict and the operation mechanism of AnQiCMS
Auto CMS is an independent application developed based on the Go language.When the AnQiCMS instance starts, it listens on a specific network port and waits for HTTP requests from clients (such as browsers).By default, AnQiCMS usually uses port 8001.On the same server, no two applications can listen on the same port at the same time; otherwise, a port conflict will occur, causing one or both programs to fail to start properly.
Therefore, the most fundamental solution to run multiple AnQiCMS instances on the same server is to allocate a unique listening port for each instance.This means that each running AnQiCMS process will provide services on different ports.
Allocate independent ports for each AnQiCMS instance
Each AnQiCMS instance's listening port is configured in the root directory of itsconfig.jsonfile. This is a crucial step to avoid port conflicts.
First, you need to make multiple copies of the AnQiCMS program files, and create a separate application directory for each instance you plan to deploy. For example, if you plan to deploy two instances, you can createanqicms_site1andanqicms_site2Two directories, and copy the complete program files of AnQiCMS to these two directories separately.
Next, enter each instance's directory, find and edit itsconfig.jsonFile. In this file, you will find a field namedport. You need to change the value of each instance to a different, unused port number.portFor example:
- For
anqicms_site1,config.jsonofportcan be set to8001. - For
anqicms_site2,config.jsonofportcan be set to8002. - This applies to each new instance, which should be assigned an incrementing port number (such as 8003, 8004, etc.), ensuring they are unique on the server.
In addition, each AnQiCMS instance also requires an independent database to store its data.During the initial installation process, you need to configure a different database name and connection information for each instance to ensure that data does not interfere with each other.If you choose to reuse the database account, you must also specify a different database name for each instance.
Access through reverse proxy
Although each AnQiCMS instance runs on a different internal port, we usually want users to access these websites through the standard HTTP (8000) or HTTPS (443) ports and their respective domain names, rather than entering them directlyyourdomain.com:8001This address. At this time, the reverse proxy server (such as Nginx or Apache) plays a key role.
The reverse proxy server acts as an intermediary between the client and the backend AnQiCMS instance.It listens to the standard 80/443 ports and forwards requests to the corresponding port of the AnQiCMS instance according to the requested domain (Host header).
Configure reverse proxy using Nginx
Nginx is a high-performance web server and reverse proxy server, very suitable for handling multi-instance deployment.
Configure an independent Nginx for each AnQiCMS instanceserverblock. For example, for the one running on port 8001anqicms_site1.comand the one running on port 8002anqicms_site2.com:
Nginx configuration example (/etc/nginx/conf.d/anqicms_site1.confor a similar path):
server {
listen 80;
server_name anqicms_site1.com www.anqicms_site1.com; # 替换为您的域名
# 根目录指向实例的 public 文件夹
root /www/wwwroot/anqicms_site1/public; # 替换为您的实际路径
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 404 =200 @AnqiCMS; # 确保404错误也能通过AnQiCMS处理
location / {
try_files $uri $uri/index.html @AnqiCMS;
}
access_log /var/log/nginx/anqicms_site1_access.log;
error_log /var/log/nginx/anqicms_site1_error.log;
}
Nginx configuration example (/etc/nginx/conf.d/anqicms_site2.conf):
"`nginx server {
listen 80;
server_name anqicms_site2.com www.anqicms_site2.com; # 替换为您的第二个域名
root /www/wwwroot/anqicms_site2/public; # 替换为您的实际路径
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_page 404 =200 @AnqiCMS;
location / {
try_files $uri $uri/index.html @AnqiCMS;
}
access_log /var/log/nginx