AnQi CMS is an efficient and customizable content management system that provides a diverse range of content display and management needs, as well as strong support for multi-site operations.For website operators, the configuration of static URLs is a key factor in improving user experience and optimizing search engine rankings.In the multi-site mode of AnQi CMS, it is particularly important to configure Nginx's pseudo-static rules properly.

Understanding AnQiCMS multi-site mode rewrite rules

Static URL, as the name implies, is a URL structure that makes dynamically generated pages look like static HTML files.This makes the URL more aesthetically pleasing, easier to remember and share, and also more friendly for search engine crawling and indexing.AnQi CMS itself supports multiple pseudo-static rules, while Nginx acts as a reverse proxy server, responsible for correctly routing external requests to the AnQi CMS backend and ensuring that these pseudo-static URLs can be correctly parsed.

In the multi-site mode of AnQi CMS, the core lies in the fact that an AnQi CMS instance can host multiple independent websites.Each website has its own domain, data, and configuration, but in many deployment scenarios, they may share the same backend service port (for example, the default port 8001).The reverse proxy responsibility of Nginx is to forward requests received from different domain names to the same Anqie CMS service, and the Anqie CMS will identify which website's request it is based on the Host header (i.e., the domain name) and return the corresponding content.The configuration of pseudo-static rules occurs at the Nginx level to ensure that the pseudo-static URLs of different sites can be correctly processed by Nginx and ultimately parsed by the Anqi CMS.

Basic configuration of Nginx as a reverse proxy

Before configuring Nginx's pseudo-static rules, we first need to ensure that Nginx is already running as the reverse proxy server for the security CMS.AnQi CMS usually runs on non-standard HTTP ports (such as 8001), while Nginx listens to standard ports 80 or 443 and forwards requests to AnQi CMS.

A typical Nginx reverse proxy configuration snippet is as follows:

server {
    listen 80;
    server_name www.yourdomain.com; # 替换为你的主域名

    root /www/wwwroot/yourdomain.com/public; # 替换为你的安企CMS站点根目录下的public文件夹

    location @AnqiCMS {
        proxy_pass http://127.0.0.1:8001; # 安企CMS后端服务端口
        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;
    }

    location / {
        try_files $uri $uri/index.html @AnqiCMS; # 尝试匹配静态文件,否则转发给AnqiCMS
    }

    # 可选:SSL 配置,如果使用HTTPS
    # listen 443 ssl;
    # ssl_certificate /path/to/your/fullchain.pem;
    # ssl_certificate_key /path/to/your/privkey.pem;
    # ...其他SSL配置...
}

In this basic configuration,server_nameDefined the domain that Nginx will listen to,rootPoints to the root directory of the site on the server (especially for the AnQi CMS project in),publicdirectory, used to store static resources).location @AnqiCMSThe block defines how to proxy requests to the AnQi CMS backend serviceproxy_passSpecifies the local address and port that the AnQi CMS listens on.Host/X-Real-IP/X-Forwarded-ForThe request header is important information forwarded to the backend, allowing Anqi CMS to identify the source and domain of the original request.

location /Block is the core of the pseudo-static rule.try_files $uri $uri/index.html @AnqiCMS;The meaning of this instruction is: Nginx first tries to find a static file that matches the request URI (such as/images/logo.png). If it cannot find a static file, it will try to findURI/index.htmlfor example/about/index.htmlIf both are not found, Nginx will internally redirect the request to@AnqiCMSblock for processing, thereby forwarding the request to the Anqicms backend.

Configuration of Nginx pseudo-static rules under multi-site mode

When extending the basic configuration to multi-site mode, we need to create an independent site for each siteserverchunk. Although all sites may point to the same AnQiCMS backend service port, Nginx will determine which one based on theHostheader to decide whichserverchunk to process the request and return the correctHostForward the header to AnQi CMS, where AnQi CMS identifies the corresponding site.

Assuming you have two sites:site1.comandsite2.comThe Nginx configuration will be as follows:

# 站点一:www.site1.com
server {
    listen 80;
    server_name www.site1.com;

    root /www/wwwroot/site1.com/public; # 站点1的public目录

    location @AnqiCMS_site1 { # 可以使用不同的命名,但通常指向同一个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;
    }

    location / {
        try_files $uri $uri/index.html @AnqiCMS_site1;
    }

    # 可选:SSL 配置
    # listen 443 ssl;
    # ssl_certificate /path/to/site1/fullchain.pem;
    # ssl_certificate_key /path/to/site1/privkey.pem;
    # ...
}

# 站点二:www.site2.com
server {
    listen 80;
    server_name www.site2.com;

    root /www/wwwroot/site2.com/public; # 站点2的public目录

    location @AnqiCMS_site2 { # 同样指向同一个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;
    }

    location / {
        try_files $uri $uri/index.html @AnqiCMS_site2;
    }

    # 可选:SSL 配置
    # listen 443 ssl;
    # ssl_certificate /path/to/site2/fullchain.pem;
    # ssl_certificate_key /path/to/site2/privkey.pem;
    # ...
}

It is noteworthy that when adding multiple sites in integrated management tools like Baota Panel, an independent Web root directory is usually created for each site, for example/www/wwwroot/site1.comand/www/wwwroot/site2.com. When configuring Nginx, be sure to point eachserverblock'srootinstruction to the subdirectory of the site in the AnQi CMS program structurepublicsuch as/www/wwwroot/site1.com/public. This is because Anqi CMS usually places static resources in this directory, while dynamic requests are ultimately forwarded to the Anqi CMS application itself.try_filesinstruction is forwarded to the Anqi CMS application itself.

After the Nginx configuration is completed, you still need to enter the AnQi CMS backend management interface to configure the internal pseudo-static rules for each site.The Anqi CMS provides various preset rules (such as number patterns, model naming patterns, category naming patterns) as well as custom patterns.try_filesThe logic matches the pseudo-static URL structure selected or customized in the AnQi CMS backend. For example, if the AnQi CMS backend is set to/archive/{id}.html, then Nginx'stry_filescan map similar/archive/123.htmlThe request is correctly forwarded to Anqicms.

Anqicms background pseudo-static rule setting

After handling request forwarding at the Nginx level, the Anqi CMS itself also needs to know how to parse these pseudo-static URLs.You can find the 'Static Rules' settings in the Function Management of Anqi CMS backend.Here are four built-in rules and one custom mode.

For example, if you select 'numeric pattern' or 'model naming pattern', Anqi CMS will generate URLs based on these rules.If the built-in rules do not meet the requirements, you can choose the "custom mode".In custom mode, you can set six groups of rules, corresponding to document details, document list, model homepage, page, tag list, and tag details.

Custom rules use variables, for example:

  • {id}: Data ID
  • {filename}: Data custom link name
  • {catname}: Category Custom Link Name
  • {catid}: Category ID
  • {module}: Model Table Name
  • {page}: Page Number

For example, a custom rule might look like this:

archive===/{module}-{id}.html
category===/{module}-{filename}(-{page})
archiveIndex===/{module}.html
page===/{filename}.html
tagIndex===/tags(-{page})
tag===/tag-{id}(-{page})

These rules define the URL format expected by Anqi CMS. Nginx'stry_filesThe instruction will capture all requests that do not directly point to static files and forward them to the Anqi CMS.An enterprise CMS further parses the URL based on these internal rules to find the corresponding controller and data.Therefore, the configuration of Nginx needs to work in coordination with the pseudo-static rules of the AnQiCMS backend, neither of which can be missing.

Operation tips

During configuration and debugging, some issues may arise. Ensure that the syntax of the Nginx configuration file is correct (you can do this bynginx -tCheck the command, and reload or restart the Nginx service after each modification.At the same time, check the AnQi CMS log to see if there are any error messages on the backend.rootpointing to itspublicdirectory, andserver_nameconsistent with the actual domain name.

By such a layered configuration, Nginx is responsible for routing frontend requests and handling static resources, while Safe CMS focuses on content management and dynamic page generation, together constructing an efficient and robust multi-site content publishing platform.


Frequently Asked Questions

Why does my Nginx configuration look correct, but some pages under multi-site still cannot be opened?First, please check the Nginx of each siteserverblock ofrootIs the path correctly pointing to the site on the server?/publicDirectory. Incorrect.rootThe path will cause Nginx to be unable to find static files or to forward requests to the wrong AnQiCMS instance.Next, confirm that Nginx has been correctly reloaded or restarted.Finally, log in to the AnQi CMS backend, check the 'pseudo-static rules' settings, ensure that the URL generation rules within AnQi CMS match the forwarding logic of Nginx, especially whether the custom URL aliases, category aliases, etc. are correctly set and unique.

I will configure all the Nginxproxy_passHow does AnQi CMS differentiate between requests from different websites when all point to the same AnQi CMS service port?When processing requests, AnQi CMS reads the HTTP request headers.HostField. In the Nginx configuration,proxy_set_header Host $host;The purpose of this instruction is to take the domain name (i.e.$hostThe value of the variable is forwarded accurately to AnQi CMS. After the AnQi CMS backend service receives the request, it will base on thisHostThe head identifies which site the current request belongs to and loads the corresponding site configuration and content. This is the key mechanism for Anqicms to implement multi-site functions.

Do I need to install an independent AnQiCMS instance for each site in multi-site mode?Generally, it is not necessary.The design of Anqi CMS allows a single core application instance to host multiple logically independent websites on the same service.serverBlock, proxy requests from different domain names to this single security CMS instance.Each website's data and configuration will be distinguished and managed internally in Anqi CMS.This greatly simplifies the complexity of deployment and maintenance.