As an experienced security CMS website operator, I am well aware of the importance of content creation, editing, publishing, and optimization, and I am also familiar with how to attract and retain users through high-quality content.The multi-site management feature of Anqi CMS is one of its core highlights, providing great convenience for users who need to manage multiple brands or sub-sites.It is crucial to properly configure Nginx's pseudo-static rules to make full use of this feature.

The following will provide a detailed explanation of the configuration example for setting Nginx pseudo-static rules for multiple sites on the Baota panel for Anq CMS.

Understand the multi-site mechanism of Anq CMS

The Anqi CMS is developed using Go language, and its multi-site management feature allows users to manage multiple independent websites under the same system and the same running instance. The system identifies the information passed through Nginx.HostThe value of the request header determines which site the user is visiting, and provides the corresponding content based on the configuration of that site.This means that, regardless of how many child sites you have, the security CMS application running in the background typically has only one instance, while Nginx plays a significant role in request distribution and URL rewriting.

Preparation in the early stage

Before configuring the Nginx pseudo-static rules, please ensure that you have completed the following preparation:

You have successfully installed the first site (main site) of Aiqi CMS on the Baota panel, whether through Docker deployment or manual deployment. The main site usually runs on some port internally on the server, for example, the default port is8001. You have parsed the domain for the main site and can access and manage it normally in the browser. You have the domain names of new sub-sites that need to be added, and these domains have been correctly resolved to your server IP address.

Create a new site and configure Nginx rewrite rules on the Baota panel

To add a new child site to AnQin CMS, it is actually creating a reverse proxy configuration for a new domain name on the Baota panel, and pointing it to the internal port where the AnQin CMS application is running.

First, please log in to your Baota panel. In the left navigation bar, select "Website" and then click "Add Site" or "Add Reverse Proxy.

For the multi-site setup of AnQi CMS, we usually choose the 'Reverse Proxy' type to create new sites because all requests will eventually be forwarded to the AnQi CMS Go application instance.

In the pop-up interface, enter the relevant information of the new site:

Domain:Enter the full domain name of your new sub-site, for examplenewsite.yourdomain.com.Proxy Name:You can fill in according to your needs, for example “Security CMS Subsite 1”.Target URL:Here you need to fill in the internal address and port where your Security CMS main application is actually running, usuallyhttp://127.0.0.1:8001Please adjust according to the actual configuration of your main site to ensure the port number is correct.

After completing the above entries, click "Submit" to create the site.

After the site is created, you need to adjust the pseudo-static (Rewrite) rules of the Nginx configuration for the site.Find the new site you just created in the "Website

Enter the site settings and switch to the "Static" tab. Clear the existing content and paste the following Nginx static rules:

    location @AnqiCMS {
        proxy_pass http://127.0.0.1:8001; # 请确保这里指向您的AnQiCMS应用实际运行的内部地址和端口
        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;
    }

Please note,proxy_passThe instructions inhttp://127.0.0.1:8001Should replace with the actual internal IP address and port that your security CMS application is listening on. The purpose of these rules is:

  • location @AnqiCMS:Defined an internal named location block for handling rewritten or missing static file requests. It forwards the request to the Anqi CMS application and passes the necessary request headers.Host/X-Real-IP/X-Forwarded-For),This is crucial for the security CMS to identify which site the request is from.
  • error_page 404 =200 @AnqiCMS;When Nginx cannot find any matching static file, it will treat the 404 error as a 200 status code and forward the request to@AnqiCMSProcess, ensure that all non-static content can be handled by the CMS application.
  • location /This is the default block that Nginx handles all requests.try_files $uri $uri/index.html @AnqiCMS;Instruction attempts to find files in order: first the requested URI ($uri) then the URI corresponds to the index.htmlfile. If these files do not exist, it will forward the request to the one defined before@AnqiCMSBlock, which is finally processed by the Anqi CMS application.So, Nginx will try to provide static files first, and if it can't find static files, it will forward the request to AnQiCMS to handle dynamic content.

After pasting the rewrite rules, be sure to click “Save” to apply changes.

Additionally, due to the characteristics of the Baota panel, even reverse proxy sites may require the configuration of a "site directory". You can set the "site directory" of this new site to the directory where the main site of the Anqi CMS is located.publicSubdirectory, for example/www/wwwroot/anqicms.com/public. This is to ensure that Nginx intry_filesThe instruction attempts to find static files and can locate the common static resources provided by the security CMS application (such as CSS, JS, images, etc.).

Add a new site configuration in AnQi CMS backend

After completing the Nginx configuration, you still need to add and configure this new site in the AnQi CMS backend management system.

Log in to the admin interface of your security CMS main site. Find the "Multi-site Management" feature in the left navigation bar and click "Add New Site.

In the form of adding a new site, you need to fill in the following key information:

  • Site Name:Fill in according to your actual needs, used for background management and identification.
  • Site root directory:This is a very important field, it determines the independent data storage location of the new site. Since AnQi CMS may run in a Docker environment, this path should usually be/app/Start. For example, if your new domain name isnewsite.yourdomain.com, you can fill in/app/newsite_yourdomain_com(which will replace the domain name with.with_To avoid directory name conflicts). Make sure to set a unique root directory for each new site, and the directory name should not be duplicated with other sites.
  • Website address:Fill in the complete access URL of your new sub-site, for examplehttp://newsite.yourdomain.com.
  • Administrator account password:Set an independent backend administrator account and password for the new site.
  • Database name:Create a separate database for the new site. It is recommended to name it in domain format, for examplenewsite_yourdomain_com.
  • Database information reuse:
  • Select the template you want to use:Choose a suitable template for the new site.

After filling in, click the “OK” button to complete the creation of the new site.

Verify the new site

Until now, your security CMS multi-site configuration has been completed. Now, you can enter the new sub-site domain in your browser (for examplehttp://newsite.yourdomain.com/Access it. If all the configurations are correct, you will see the homepage of the new site. You can also access it throughhttp://newsite.yourdomain.com/system/Access the backend management interface of the new site and log in using the administrator account and password you set in the Anqi CMS backend.

Common Questions (FAQ)

1. How does AnQi CMS distinguish and display the content of different sites under the same running instance?

AnQi CMS passes through Nginx reverse proxy.HostRequests come from different sites. When users visitnewsite.yourdomain.comNginx will forward the request to the Anqi CMS application and include it in the request header.Host: newsite.yourdomain.comEnglish version: . The AnQi CMS application will parse thisHostThe head, according to the "Multi-site Management" configuration in the background and the "Site Address" to match the corresponding site, and load the database, template and other configuration information of the site, thereby achieving the isolation and display of multi-site content.

2. Can I set independent Nginx configurations for each sub-site, such as different SSL certificates or caching strategies?

Yes, you can.When creating Nginx sites individually for each subdomain in the Baota panel, each site will have its own independent Nginx configuration file.