As an experienced CMS website operation person in an enterprise, I am well aware of the importance of content creation, editing, publishing, and optimization, and also know how to attract and retain users through high-quality content.The multi-site management function 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 fully utilize this feature and correctly configure the Nginx pseudo-static rules.
The detailed explanation of setting up Nginx pseudo-static rules for multiple sites on the Baota panel for AnQi CMS.
Understanding the multi-site mechanism of AnQi CMS.
The Anqi CMS is developed using Go language, 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 request header determines which site the user is visiting and provides the corresponding content based on the configuration of the 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 crucial role in request distribution and URL rewriting.
Preparation work
Before configuring the Nginx pseudo-static rules, please make sure you have completed the following preparations:
You have successfully installed the first site (main site) of AnQi CMS on the Baota panel, whether through Docker deployment or manual deployment. The main site usually runs on a port inside the server, such as the default port.8001.
You have parsed the domain for the main site and can access and manage it in the browser.You have the domain name for the new sub-site that needs 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 for AnQi CMS, it is actually to create a reverse proxy configuration for a new domain name on the Baota panel and point it to the internal port where the AnQi 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 a new site because all requests will eventually be forwarded to the Go application instance of AnQi CMS.
Fill in the relevant information for the new site in the pop-up interface:
Domain:Enter the complete domain name of your new sub-site, for examplenewsite.yourdomain.com.Proxy name:You can fill in according to your needs, for example, "AnQi CMS Substation 1".Target URL:Please fill in the actual internal address and port of your AnQi CMS main application, which is usuallyhttp://127.0.0.1:8001Please adjust the configuration of your main site according to actual settings, ensuring that 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 rewrite rules of the Nginx configuration for the site.Find the new site you just created in the "Website" list, click the "Settings" button on the right.
After entering the site settings, 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_passIn the command of thehttp://127.0.0.1:8001Replace with the actual internal IP address and port that your Anqicms application is listening on. The purpose of these rules is:
location @AnqiCMSIt defines an internally named location block used to handle rewritten or missing static file requests. It forwards the request to the Anqic CMS application and passes the necessary request header information (Host/X-Real-IP/X-Forwarded-ForThis is crucial for the Anq CMS to identify which site the request is from.error_page 404 =200 @AnqiCMS;When Nginx cannot find any matching static files, it will handle the 404 error as a 200 status code and forward the request to@AnqiCMSProcess, ensure that all non-static content can be processed by the Aiqi CMS application.location /This is the default block that Nginx processes all requests.try_files $uri $uri/index.html @AnqiCMS;The command attempts to find files in order: first the requested URI ($uri), then the correspondingindex.htmlfile. If these files do not exist, it will forward the request to the one previously defined@AnqiCMSThe block is finally processed by the AnQi CMS application. In this way, Nginx will first try to provide static files, and if it cannot find static files, it will forward the request to AnQiCMS to handle dynamic content.
After pasting the pseudo-static rules, be sure to click "Save" to apply the changes.
Moreover, due to the characteristics of the Baota panel, even reverse proxy sites may need to configure a "website directory". You can set the "website directory" of the new site to the directory where the Anqi CMS main site is located.publicsuch as/www/wwwroot/anqicms.com/public. This is to ensure that Nginx is runningtry_filesThe command attempts to find static files and is able to locate the public static resources provided by the Anqin 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 backend management interface of your Anqin CMS main site. Find the 'Multi-site Management' feature in the left navigation bar and click 'Add New Site'.
In the form for 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 is usually set to
/app/Starting. For example, if your new domain name isnewsite.yourdomain.comyou can fill in/app/newsite_yourdomain_com(including the domain name within).Replace_To avoid directory name conflicts). Make sure to set a unique root directory for each new site, and the directory name does not conflict with other sites. - Website address:Enter the full access URL of your new sub-site, for example
http://newsite.yourdomain.com. - Admin account password:Set up an independent backend admin account and password for the new site.
- Database name:Create an independent database for the new site. It is recommended to name it in domain format, for example
newsite_yourdomain_com. - Database information reuse: If your AnQi CMS is installed with Docker and the MySQL database is also in Docker, you can choose to 'Reuse default database account information' because AnQi CMS in the Docker environment usually has all the database management permissions.If you deploy the database elsewhere, you need to fill in the database connection information truthfully.
- Select the template to use:Choose a suitable template for the new site.
Click the “OK” button to complete the creation of the new site after filling in.
Verify the new site
Your CMS multi-site configuration is now complete. Now, you can enter the domain name of the new sub-site in your browser (for examplehttp://newsite.yourdomain.com/Access it. If everything is configured correctly, you will see the homepage of the new site. You can also access it byhttp://newsite.yourdomain.com/system/Visit the background management interface of the new site and log in using the administrator account and password you set in the Anqi CMS background.
Frequently Asked Questions (FAQ)
1. How does AnQi CMS differentiate and display content for different sites under the same running instance?
AnQi CMS passes through Nginx reverse proxy.HostThe request header identifies different sites. When the user visitsnewsite.yourdomain.comNginx will forward the request to the Anqi CMS application and include it in the request header.Host: newsite.yourdomain.com. The AnQi CMS application will parse thisHostThe header, according to the "Multi-site Management" configuration of the background "Site Address" to match the corresponding site, and load the database, template and other configuration information of the site, thus realizing the isolation and display of multi-site content.
2. Can I set up independent Nginx configurations for each sub-site, such as different SSL certificates or caching policies?
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.This means you can configure SSL certificates separately for each site (in the 'SSL' tab of the Baota panel), set independent cache rules, or add specific Nginx