Precise management, efficient obstacle avoidance: How AnQiCMS multi-site deployment cleverly avoids port conflicts

As an experienced website operations expert, I know that in the current Internet environment of multiple brands, multiple businesses, and multiple regions developing in parallel, efficiently and stably managing multiple websites is the key to the success of enterprise content operations.AnQiCMS, this is a powerful content management system developed based on the Go language, with its excellent multi-site management capabilities, it has undoubtedly become a powerful assistant for many operation teams.However, when we deploy AnQiCMS's multi-site to the same server, a seemingly simple but often troublesome technical problem for beginners emerges: how to avoid potential port conflicts between different sites?

Today, let's delve deep into this issue and provide a practical and easy-to-understand solution to ensure smooth and worry-free multi-site deployment of your AnQiCMS.

Understand AnQiCMS's multi-site philosophy

Let's review how AnQiCMS designs its multi-site management feature.One of the core strengths of AnQiCMS is the 'Multi-site Management' feature, which allows users to create and independently manage multiple brands, sub-sites, or content branches through a simple and efficient system architecture.This means that in many cases, you do not need to deploy a brand new AnQiCMS application for each independent website.

On the contrary, AnQiCMS provides a more elegant solution:An AnQiCMS application instance, through its powerful backend management features, can simultaneously support multiple independent front-end websites. These websites are logically independent, each having its own domain, content, template, and even database (an independent database can be selected in configuration), but physically, they may all be served by the same AnQiCMS application instance.This design greatly reduces resource consumption and maintenance costs.

Port conflict: why it occurs, how to avoid it?

AnQiCMS is an application developed in Go language, which listens to a specific port when it starts, such as the default one8001. This is the entry point it provides for external services. If only one AnQiCMS instance is running on your server, it listens8001There is no problem with the port. However, when you want to deploy multiple AnQiCMS 'instances' (i.e., multiple completely independent AnQiCMS application copies, not the built-in multi-site of AnQiCMS) on the same server, or even if there is only one AnQiCMS instance but you need to handle multiple domain names, you may encounter port conflicts.

The core strategy of avoidance, no matter which deployment scenario, cannot do without a key role of a 'scheduler' -Reverse proxy server.

1. The magic of reverse proxy: unified externally, internal scheduling

Reverse proxy servers (such as Nginx or Apache) are the foundation for solving port conflicts.It plays the role of an intelligent traffic scheduler. When external users access your website through a domain name, the request first reaches the reverse proxy server.The reverse proxy does not return AnQiCMS content directly, but forwards the request to the actual port where AnQiCMS runs on the backend according to the predefined rules (usually the domain).This way:

  • Unified externally:All websites can be accessed through standardHTTP(80)orHTTPS(443)port access, users do not need to remember complex port numbers.
  • Internal isolation:The AnQiCMS application can run on any non-standard port (such as 8001, 8002, etc.), and there will be no conflicts between them because external requests never directly reach these ports.

The flexibility of this mode lies in that whether you are running an AnQiCMS instance to serve multiple logical sites or running multiple AnQiCMS instances, the reverse proxy can perform perfectly.

2. Scenario one: One AnQiCMS instance manages multiple sites (recommended)

This is the most common and recommended usage of the AnQiCMS multi-site function. You only need to run one instance of the AnQiCMS application on the server, which may listen8001Port. Then, through the AnQiCMS backend "Multi-site Management" feature, add your new site, and specify a separate domain, root directory, and database for each new site.

In this mode, all requests made by the browser to different domains (such aswww.siteA.com/www.siteB.comAll requests will first reach your reverse proxy server. The reverse proxy will forward all these requests to the unique AnQiCMS instance that is listening on the backend.8001Port. The AnQiCMS application automatically recognizes and renders the page content of the corresponding site after receiving a request based on the domain information in the request header.

Reverse proxy configuration example (for Nginx):

Assuming your AnQiCMS main instance is running inhttp://127.0.0.1:8001.

# 站点 A 的配置
server {
    listen 80;
    server_name www.siteA.com;
    
    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;
    }
    error_page 404 =200 @AnqiCMS; # 确保所有请求都经过AnQiCMS处理,包括伪静态
    location / {
       try_files $uri $uri/index.html @AnqiCMS;
    }
}

# 站点 B 的配置
server {
    listen 80;
    server_name www.siteB.com;

    location @AnqiCMS {
        proxy_pass http://127.0.0.1:8001; # 注意,这里仍然指向同一个AnQiCMS实例的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;
    }
    error_page 404 =200 @AnqiCMS;
    location / {
       try_files $uri $uri/index.html @AnqiCMS;
    }
}

In the AnQiCMS backend, you still need to add in the "Multi-site Management".www.siteA.comandwww.siteB.comThese logical sites. Integrated management tools such as Baota panel, 1Panel, or aaPanel usually provide a simplified interface to complete the creation of these reverse proxy and AnQiCMS backend sites.

3. Scenario two: multiple AnQiCMS instances, each with a separate port (highly isolated)

Under certain specific scenarios, you may want to run multiple instances on the same server for reasons such as version isolation, performance independence, and testing environment requirements.Totally independentof the AnQiCMS application instance. At this time, the key to avoiding port conflicts is to allocate a separate internal listening port for each AnQiCMS instance.a unique internal listening port..

For example, the first AnQiCMS instance listens8001The second instance listens8002The third instance listens8003And so on. Each AnQiCMS application listens to its ownconfig.jsonThe file needs to make corresponding port modifications (such as, changeport: 8001changed toport: 8002)

Reverse proxy configuration example (for Nginx):

AssumesiteC.comBy listening8002The AnQiCMS instance on the port provides services,siteD.comBy listening8003The AnQiCMS instance on the port provides services.

`nginx

Configuration of site C

server {

listen 80;
server_name www.siteC.com;

location @AnqiCMS_C {
    proxy_pass http://127.0.0.1:8002; # 指