As an experienced CMS website operation person in the constantly evolving digital environment, I know that it is crucial to manage multiple websites flexibly and efficiently.The Aanqi CMS provides a solid foundation for us with its Go language's high concurrency features 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 elaborate on 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.

Understand the essence of port conflict and the operation mechanism of AnQiCMS

AnQi CMS is an independent application developed based on the Go language.When the AnQiCMS instance starts, it will listen on a specific network port and wait for HTTP requests from clients (such as browsers).By default, AnQiCMS usually uses port 8001.On the same server, no two applications can listen to the same port at the same time; otherwise, a port conflict will occur, causing one or both programs to fail to start normally.

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.

Assign an independent port for each AnQiCMS instance

The listening port of each AnQiCMS instance is under its root directoryconfig.jsonand is configured in the file. This is a critical step to avoid port conflicts.

First, you need to make copies of the AnQiCMS program files, creating a separate application directory for each instance you plan to deploy. For example, if you are going to deploy two instances, you can createanqicms_site1andanqicms_site2Two directories, and copy the complete program files of AnQiCMS separately to these two directories.

Next, enter the directory of each instance, find and edit itsconfig.jsonfile. In this file, you will find a field namedport. You need to change each instance of theportto a different, unused port number. For example:

  • Foranqicms_site1,config.jsonofportcan be set to8001.
  • Foranqicms_site2,config.jsonofportcan be set to8002.
  • As such, each new instance 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 initialization installation process, you need to configure different database names and connection information for each instance to ensure that the 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 entry through reverse proxy

Although each AnQiCMS instance runs on a different internal port, it is usually desired that users access these websites through standard HTTP (8000) or HTTPS (443) ports and their respective domain names, rather than entering them directlyyourdomain.com:8001This is the address. At this time, the reverse proxy server (such as Nginx or Apache) plays a crucial 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 AnQiCMS instance on the corresponding backend port based on the domain name (Host header).

Configure reverse proxy using Nginx

Nginx is a high-performance web server and reverse proxy server, very suitable for handling multiple 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