As a senior CMS website operation personnel of a well-known security company, I am well aware that the efficient operation of a content management system is crucial for website operators, especially when it comes to multi-site management and SEO optimization.The AnQi CMS, developed in Go language with its high performance and flexible multi-site support, provides us with a powerful content publishing and management platform.Today, I will introduce in detail how to configure pseudo-static rules for multi-site AnQiCMS in the Nginx environment, ensuring that your website can enjoy optimized URL structure and smooth access experience.

Deeply understand the AnQiCMS multi-site and pseudo-static mechanism

Before configuring Nginx's rewrite rules, we first need to understand the underlying mechanism of AnQiCMS handling multiple sites and rewrite requests.AnQiCMS as a modern content management system, its "multi-site management" feature allows us to create and manage multiple independent websites under a single AnQiCMS application instance.This means that, regardless of how many sites there are, there may only be one AnQiCMS application running in the backend, which identifies incoming requests byHostDetermine which site the user is visiting and load the corresponding site's data and content accordingly.

As for "pseudo-static", AnQiCMS has built-in multiple pseudo-static rule configurations, such as number patterns, model naming patterns, category naming patterns, etc. These rules define the URL structure displayed in the browser for website content (such as articles, categories, single pages, etc.). For example, the URL of an article may start from/archive.php?id=123Made more readable and SEO-friendly/news/article-123.htmlThese pseudo-static rules are parsed and handled by the AnQiCMS application itself.The role played by Nginx here is not to perform complex URL rewriting, but to forward all requests that cannot be directly matched to static files (such as images, CSS, JS) to the backend AnQiCMS application, where AnQiCMS will handle the subsequent URL parsing and content distribution.

Basic Nginx Reverse Proxy Configuration

Nginx is an ideal choice for deploying AnQiCMS as a high-performance web server and reverse proxy server.The core function of reverse proxy is to forward the client's requests to the internal application server and return the responses from the application server to the client.For AnQiCMS, it is usually deployed on some internal port (such as the default 8001), while Nginx listens to the standard HTTP/HTTPS ports (such as 80/443), responsible for receiving external requests and forwarding them to AnQiCMS.

A basic Nginx reverse proxy configuration snippet usually includesproxy_passCommand used to specify the address and port of the AnQiCMS application, as well asproxy_set_headerCommand used to correctly transfer the original request header information of the client (especiallyHostThe header and client IP address are passed to AnQiCMS, which is crucial for AnQiCMS to identify the correct site and record the user's IP address.

This is a basic Nginx for a single AnQiCMS instance regardless of how many sites it manageslocationConfiguration example, usually placed in your Nginx site configuration fileserverWithin block:

location @AnqiCMS {
    proxy_pass http://127.0.0.1:8001; # 请替换为AnQiCMS实际运行的IP和端口
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    # 更多HTTP头,例如:
    proxy_set_header   X-Forwarded-Proto $scheme;
}

error_page 404 =200 @AnqiCMS; # 当Nginx找不到文件时,将请求转发给AnQiCMS处理

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

This configuration means that Nginx first tries to find the requested URI's corresponding static file in the root directory of the website (usually AnQiCMS'spublicdirectory) orindex.htmlIf found, directly return the static resource. If not found, forward the request to named@AnqiCMSinternallocationblock, which will proxy the request tohttp://127.0.0.1:8001(Your AnQiCMS application listens to the address and port).error_page 404 =200 @AnqiCMS;Ensure that even 404 errors considered at the Nginx level are also forwarded to AnQiCMS for processing so that AnQiCMS can handle its internal URL routing or display a custom 404 page.

Configure AnQiCMS backend multi-site

Before configuring multiple site pseudo-static in Nginx, you need to complete the creation of the new site in the AnQiCMS backend.The design of AnQi CMS allows a single application instance to manage multiple independent sites, which greatly simplifies operations.

In the AnQiCMS background that has been installed and running, new sites are usually added through the 'Multi-site Management' feature. During the process of adding a new site, you need to specify the following key information:

  • Site name: It is used to identify your site.
  • Site root directory: This path is used by AnQiCMS to store independent data of this site (such as cache, uploaded files, etc.). It is recommended to use/app/Start (if it is a Docker environment), add the domain name with dots replaced by underscores, for example/app/dev_anqicms_comEnsure data isolation between different sites.
  • website address:You will use the domain name to access the new site, for examplehttp://dev.anqicms.com. AnQiCMS will match requests based on this domain.
  • Database nameEach site should have an independent database, and it is also recommended to use domain names with underscores instead of dots, for exampledev_anqicms_com.
  • Administrator account passwordSet up independent backend management credentials for the new site.
  • Template: Choose the template suitable for the new site.

After completing these configurations, AnQiCMS is ready to respond to requests from the new site.

Nginx reverse proxy AnQiCMS multi-site pseudo-static rules configuration

For the multi-site feature of AnQiCMS, Nginx configuration does not need to write different pseudo-static rules for each site because AnQiCMS itself willHostThe header identifies different sites. Nginx only needs to configure a separate one for each domain.serverBlock it and forward all requests to the same AnQiCMS application instance.

Here is a complete example of a Nginx multi-site configuration, assuming your AnQiCMS application is running inhttp://127.0.0.1:8001and you havewww.anqicms.comanddev.anqicms.comTwo sites:

`nginx

Define the upstream server for AnQiCMS application

upstream anqicms_backend {

server 127.0.0.1:8001; # AnQiCMS应用监听的地址和端口
keepalive 64;

}

AnQiCMS public proxy configuration, can be reused

location @AnqiCMS_proxy {

proxy_pass http://anqicms_backend;
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;
proxy_redirect     off;
proxy_buffering    off;
proxy_http_version 1.1;
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;

}

The first site: www.anqicms.com

server {

listen 80;
server_name www.anqicms.com;
root /www/wwwroot/anqicms/public; # AnQiCMS应用存放静态资源的public目录

#