As an experienced security CMS website operation person, 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 URL is an indispensable part, which not only makes the website URL structure more concise and beautiful, but also significantly improves the efficiency of search engines in capturing and understanding the content of the website.AnQiCMS was designed with this in mind from the very beginning, with built-in powerful pseudo-static management functions. However, to maximize its effectiveness, the configuration of Nginx pseudo-static rules on the server side is crucial.

This article will guide you in detail on how to configure Nginx pseudo-static rules for your AnQiCMS website on the Baota panel.This configuration is designed to correctly forward all requests that match the pseudo-static pattern to the AnQiCMS application, while ensuring that static resources can be loaded efficiently, thereby optimizing the overall performance and SEO of the website.

Preparation work before configuration

Before you start configuring the Nginx rewrite rules, please confirm that your server environment is ready.You need to ensure that the Baota panel is successfully installed, and your AnQiCMS website has been successfully deployed through the Baota panel (whether through the Go project or Docker), and the corresponding domain has been bound.127.0.0.1:8001Port is running, Nginx configuration is responsible for proxying external requests to this port.

Understand the pseudo-static mechanism of AnQiCMS

AnQiCMS provides flexible pseudo-static management functions, allowing website administrators to customize URL structures according to content types (such as articles, products, single pages, tags, etc.) and personal preferences.In the function management of AnQiCMS background, you can find the 'Static Rules' option, select the preset mode (such as number mode, model naming mode, category naming mode) or enter the advanced custom mode.These internal settings define how the AnQiCMS application itself will generate and parse friendly URLs for various contents.The function of Nginx rewrite rules is to act as a bridge at the server level, ensuring that when users or search engines access these friendly URLs, Nginx can forward them seamlessly to the AnQiCMS application for processing, rather than directly searching for non-existent files in the file system.

Configure Nginx pseudo-static rules in the Baota panel

Configure Nginx rewrite rules is the key step to ensure the normal operation of AnQiCMS rewrite links. Please follow the following instructions to operate on the Baota panel:

First, log in to your Baota panel.In the left navigation menu, click the "Website" option.On 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.

Enter the website settings interface and you will see multiple configuration tabs.First, click the "Website Directory" tab.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 dynamic content is handled by the application.Please make sure to click Save after the settings are completed.

Next, switch to the "pseudo-static" tab.This is the core area where we configure Nginx's pseudo-static rules.Please paste the complete Nginx configuration code into the text box.This code is necessary for the pseudo-static operation of AnQiCMS to run normally.After pasting, click the save button.If you wish 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 http://127.0.0.1:8001;
    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 pseudo-static rules 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 otherlocationWhen the block needs to forward the request to the AnQiCMS application, it will refer to this block.proxy_pass http://127.0.0.1:8001;It is a core instruction that tells Nginx to proxy all requests forwarded to this block.http://127.0.0.1:8001Port, this is the address and port that the AnQiCMS application usually listens to.proxy_set_headerSeries instructions are 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 Nginx, if a request in the file system does not find the corresponding static file, resulting in Nginx returning a 404 error, then Nginx should not send a 404 response directly to the client.