How to configure Nginx pseudo static rules in AnQiCMS multi-site mode?

Calendar 👁️ 62

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 https://en.anqicms.com; # 安企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 https://en.anqicms.com;
        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 https://en.anqicms.com;
        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.

Related articles

What is the practice of installing multiple AnQiCMS sites on the same server?

As an experienced CMS website operation person, I know how important it is to manage multiple websites efficiently on a single server.The AnQi CMS was designed with the need for multi-site management in mind, providing users with a flexible and powerful solution.The following article will detail the **practice** of installing and managing multiple AnQiCMS sites on the same server.

2025-11-06

How to troubleshoot and fix errors after AnQiCMS installation fails?

As an experienced CMS website operation personnel of a security company, I know that the stable operation of the website and the efficient management of content are the foundation of business success.AnQiCMS with its efficient, concise architecture in Go language and rich enterprise-level features, has won the favor of many users.However, even the most excellent system may encounter unexpected problems during the installation and deployment process.When AnQiCMS installation fails, this may not only delay the progress of going online, but also affect the subsequent operation plan.

2025-11-06

How to solve the common database permission insufficient problem when installing AnQiCMS?

When deploying AnQi CMS, database configuration is a crucial link in the entire installation process.Among them, insufficient database permissions are a common cause of installation failure.When the system fails to create a database, create a data table, or cannot perform data read/write operations on the database, it will usually prompt such permission-related errors.As a website operator, it is essential to deeply understand and master how to diagnose and solve these database permission issues to ensure the smooth launch and stable operation of AnQiCMS.

2025-11-06

How to deploy AnQiCMS on the old Baota panel (non-Go project)?

AnQiCMS is an enterprise-level content management system developed based on the Go language, known for its high efficiency, security, and customizable features, making it an ideal choice for many small and medium-sized enterprises and content operation teams.As a long-term website operator dealing with AnQiCMS, I am well aware of the importance of the convenience of system deployment to operational efficiency.

2025-11-06

How to configure reverse proxy for AnQiCMS on Apache server?

AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, known for its high performance, security, and ease of use.It is usually not recommended to expose the application listening port (such as the default 8001) directly to the external network when deploying this type of application.On the contrary, by configuring a reverse proxy such as Apache, a more secure, more stable, and feature-rich access method can be provided for the AnQiCMS website.By configuring Apache to set up reverse proxy, you can achieve many advantages: First

2025-11-06

How to configure AnQiCMS's Nginx proxy in the Linux command line environment?

As a senior CMS website operation person in an enterprise, I know that stable and efficient deployment is the foundation of successful website operation.Under Linux, Nginx, as a high-performance reverse proxy server, is the ideal partner for AnQiCMS, and can effectively improve the speed and security of website access.I will introduce in detail how to configure Nginx in the Linux command line environment to provide a stable and reliable reverse proxy service for AnQiCMS.

2025-11-06

How to set up AnQiCMS to start automatically on Linux server (Crontab)?

As an experienced security CMS website operations personnel, I am well aware of the importance of stable website operation, especially after an unexpected server restart, when the system can automatically restore services, which is crucial for ensuring user access experience and avoiding operation interruption.AnQiCMS (AnQiCMS) is an efficient and concise content management system developed in Go language, with flexible deployment methods, but how to ensure it starts up automatically on Linux servers is a concern for many operators.

2025-11-06

How to perform local development and testing of AnQiCMS in Windows environment?

As an operator who is deeply familiar with the operation of AnQiCMS, I fully understand the importance of sufficient local development and testing before formal launch to ensure the quality of website content, user experience, and system stability.Set up an efficient AnQiCMS local development environment under the Windows environment, which allows you to freely create, edit, publish, and optimize content, while also performing various function tests, thereby greatly improving work efficiency.The following will elaborate on how to carry out local development and testing of AnQiCMS in a Windows environment.###

2025-11-06