How to configure Nginx pseudo-static rules for AnQiCMS on the Baota panel?
As an experienced CMS website operation manager for a security company, I am well aware of the decisive role of efficient content management and excellent search engine optimization (SEO) in the success of a website.Static page generation is an indispensable part of it, not only does it make the URL structure of the website simpler and more beautiful, but more importantly, it can significantly improve the search engine's ability to capture and understand the content of the website.AnQiCMS was designed with this point in mind from the beginning, built-in with powerful pseudo-static management functions, but to maximize its effectiveness, the Nginx pseudo-static rule configuration on the server side is crucial.
This article will provide a detailed guide on how to configure Nginx pseudo-static rules for your AnQiCMS website in the Baota panel.This configuration is designed to correctly forward all requests that match the pseudo-static mode to the AnQiCMS application, while ensuring that static resources can be loaded efficiently, thereby optimizing the overall performance and SEO of the website.
Preparation before configuration
Before you start configuring Nginx's pseudo-static rules, please confirm that your server environment is ready.You need to make sure that the Baota panel is successfully installed, and your AnQiCMS website has been successfully deployed through the Baota panel (whether through a Go project or Docker), and the corresponding domain has been bound.The AnQiCMS application is usually local127.0.0.1:8001The port is running, the Nginx configuration will be responsible for proxying external requests to this port.
Understand the pseudo-static mechanism of AnQiCMS
AnQiCMS provides flexible pseudo-static management features, allowing website administrators to customize URL structures according to content types (such as articles, products, single pages, tags, etc.) and personal preferences.In the AnQiCMS backend feature management, you can find the 'Static rules' option, select preset modes (such as number mode, model naming mode, category naming mode) or enter advanced custom mode.These internal settings define how the AnQiCMS application itself generates and parses friendly URLs for various content.The role of Nginx's pseudo-static rules is to act as a bridge at the server level, ensuring that when users or search engines access these friendly URLs, Nginx can seamlessly forward them to the AnQiCMS application for processing, rather than directly searching for non-existent files in the file system.
Configure Nginx rewrite rules in Baota panel
Configure Nginx rewrite rules is the key step to ensure that AnQiCMS rewrite links work normally. Please follow the following instructions in the Baota panel:
First, log in to your Baota panel. Click the 'Website' option in the left navigation menu.In the website list, find the AnQiCMS website you have deployed and click the "Settings" button in the operation column to enter the detailed configuration interface of the website.
After entering the website settings interface, you will see multiple configuration tabs.First, click the "Website Directory" tab. Here, you need to set the website "runtime directory" to the root directory of your AnQiCMS.publicFolder. For example, if your AnQiCMS project files are stored in/www/wwwroot/yourdomain.com, then the correct running directory should be set to/www/wwwroot/yourdomain.com/public. This is because the static resources (such as CSS, JS, images, etc.) of AnQiCMS are stored in this directory by default, while the dynamic content is processed by the application.After setting up, please be sure to click Save.
Next, switch to the "pseudo-static" tab. This is the core area for configuring Nginx pseudo-static rules.Please paste the following Nginx configuration code into the text box.This code is necessary for the normal operation of AnQiCMS pseudo-static pages.After pasting, click the save button. If you want to save this rule for future quick application to other AnQiCMS websites, you can also choose the 'Save as template' option.
location @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;
}
error_page 404 =200 @AnqiCMS;
location / {
try_files $uri $uri/index.html @AnqiCMS;
}
Nginx rewrite rule parsing
Let's briefly analyze this Nginx configuration code to help you understand its working principles:
location @AnqiCMS { ... }Defined a named@AnqiCMSinternal Location block. When otherlocationThe block needs to forward the request to the AnQiCMS application when this block is referenced.proxy_pass https://en.anqicms.com;It is a core instruction that tells Nginx to proxy all requests forwarded to this block.https://en.anqicms.comPort, this is the address and port that the AnQiCMS application usually listens to.proxy_set_headerThe series of commands is used to ensure that AnQiCMS can correctly obtain the original request information from the client, such as the real Host, IP address, etc.
error_page 404 =200 @AnqiCMS;This line is the key to implementing pseudo-static. It indicates that if Nginx does not find the corresponding static file in the file system for a request, causing Nginx to return a 404 error, then Nginx should not send a 404 response directly to the client. Instead,