AnQiCMS content management system, with its efficient features based on the Go language and SEO-friendly design concept, is gradually becoming the preferred tool for small and medium-sized enterprises and content operation teams.As a veteran who has been deeply involved in website operations for many years, I know the importance of high-quality content and excellent user experience, and an elegant URL structure is the key to improving these experiences.The built-in pseudo-static function of AnQiCMS is exactly for achieving this goal.
For many websites running on Linux, Baota panel has become a popular server management tool due to its intuitive and easy-to-use interface.After installing AnQiCMS on the Baota panel, correctly configuring the Nginx pseudo-static rules is an essential step to ensure that the website content can be effectively crawled by search engines and improve user access experience.
AnQiCMS rewrite mechanism analysis
Static URL technology does not actually exist as a file or directory, but is simulated by the rewrite rules of web servers (such as Nginx or Apache) to mimic the form of static HTML pages for dynamically generated URLs.The benefits of this are multifaceted: it makes the URL simpler and more meaningful, enhancing the user's understanding of the website structure; at the same time, static URLs are more friendly to search engine crawlers, helping to improve the website's SEO ranking.
AnQiCMS is well-versed in this, and its core features include powerful pseudo-static and 301 redirect management.The system provides a variety of built-in static rules, such as number patterns, model naming patterns, and category naming patterns to meet the needs of different websites.In addition, AnQiCMS also allows users to customize the static rule configuration, providing high flexibility to shape the ideal URL structure.These backend settings need to be coordinated with the actual rules of the web server in order to function properly.
Configure Nginx pseudo-static rules in the Baota panel
On Baota panel, configure Nginx rewrite rules for AnQiCMS, which is essentially telling the Nginx server how to handle requests pointing to the AnQiCMS application.This process requires us to modify the Nginx configuration file of the corresponding website in the Baota panel website settings.
First, log in to your Baota panel, navigate to the "Website" option in the left menu.Find the website where you have installed AnQiCMS and click the 'Settings' button on the right.In the popped-up website settings window, select the 'Static URL' tab.
In most cases, the Nginx pseudo-static rules recommended by AnQiCMS official are as follows:
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;
}
Please copy and paste this code into the pseudo-static configuration area of the Baota panel. Now, let's delve into the meaning of this rule:
location @AnqiCMS { ... }: This is named as@AnqiCMSThe internal location block. It defines how Nginx should handle when requests are forwarded to the AnQiCMS application.proxy_pass http://127.0.0.1:8001;This line is crucial, it indicates that Nginx will proxy all matching requests to the local127.0.0.1:8001address. Here is8001Is the default port that the AnQiCMS application listens to. If you changed the port when installing AnQiCMS, please be sure to replace it with your actual port number.proxy_set_header Host $host;/proxy_set_header X-Real-IP $remote_addr;/proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;These instructions are used to set the HTTP request headers.They ensure that the AnQiCMS application can correctly obtain the real IP address and Host information of the client, which is crucial for security, logging, and multi-site management.error_page 404 =200 @AnqiCMS;This directive tells Nginx that when the server cannot find the requested resource (returns a 404 error), it should not directly display the 404 error page but instead rewrite the request internally and forward it to@AnqiCMSThis location block, and returns a 200 status code. This is necessary for AnQiCMS to handle custom 404 pages and pseudo-static routing.location / { ... }This is the general rule that Nginx processes all root path requests.try_files $uri $uri/index.html @AnqiCMS;This is the key to Nginx's pseudo-static configuration. It tries to find files in order.$uriAttempt to find the file that matches the URI exactly. For example, if the request/css/style.cssNginx will try to find the website root directory under thecss/style.cssfile.$uri/index.html: If the previous step fails, Nginx will try to find the directory corresponding to the URI underindex.htmlfile.@AnqiCMSIf the first two steps fail, it means that the requested URI is neither a static file nor the index.html in the directory, so Nginx will internally rewrite and forward it to the one previously defined@AnqiCMSThis location block, thus passing the request to the AnQiCMS application for processing.This is the principle of pseudo-static, all non-static resource requests will be taken over by the AnQiCMS router.
Activate and test the Nginx pseudo-static configuration
Paste the above Nginx rules into the pseudo-static configuration area of the Baota panel and click the "Save" button.After saving, the Baota panel will usually automatically prompt you whether to restart the Nginx service.You must necessarily choose to restart Nginx so that the new configuration takes effect.
After Nginx service restart, you can visit your AnQiCMS website through the browser for testing.Try to access the homepage, article detail page, category page, etc., check if the URL is displayed in a pseudo-static form, and whether the page content can be loaded normally./article/123.htmlinstead of/index.php?id=123This means that the Nginx configuration is initially effective.
Pseudo-static rule selection for AnQiCMS backend
It is not enough to just configure Nginx, the AnQiCMS backend also needs corresponding settings to work with the Nginx rules.Log in to your AnQiCMS backend management interface, navigate to the 'Feature Management' under the 'Static Rule' option.
Here, you can see the various pseudo-static rule patterns built into AnQiCMS.These patterns determine how AnQiCMS generates URL links internally and how it parses incoming requests.You need to choose a mode that can work with Nginx configuration according to your needs.
- Numeric pattern: Typically, URLs include the ID of the article or category, such as
/article-1.html. - Model naming pattern: URLs include the alias and ID of the model, such as
/article/1.htmlor/product/item-1.html. - Category naming pattern: The URL will include the alias of the category and the article ID, such as
/category-name/1.html.
Make sure that the rules defined in the AnQiCMS backend match the Nginx'stry_filesThe command logic is compatible.AnQiCMS will generate the corresponding URL based on the mode you choose, and Nginx is responsible for rewriting these pseudo-static URLs correctly to the AnQiCMS application for processing.The cooperation of both is the key to the successful implementation of pseudo-static.
Advanced Static Rule Customization
AnQiCMS provides powerful custom static function, allowing you to finely control the URL structure according to your business needs.On the "static rules
{id}Data ID{filename}Custom Data Link Name (e.g., article URL alias){catname}Custom Category Link Name{catid}Category ID{module}Model Table Name{page}Page Number
By combining these variables, you can create a highly personalized URL structure. For example, you can define the URL for the article detail page as/{module}/{catname}/{filename}.htmlOr even more concise/{module}-{id}.html.In the custom mode, AnQiCMS will generate frontend links according to the rules you set, while Nginx uses its rewriting capabilities to ensure that these links correctly point to the application.
Summary
To configure the Nginx pseudo-static rules for AnQiCMS on the Baota panel is a process involving dual settings of both the front-end server and the back-end CMS system. By adding the correcttry_filesrules andproxy_passInstruct, and combined with the AnQiCMS backend to select or customize the pseudo-static mode, you can build a neat, SEO-friendly, and user-friendly URL structure for your website.This not only helps to improve the visibility of the website in search engines, but also makes the content of your website more professional and attractive.
Frequently Asked Questions (FAQ)
Q1: After configuring Nginx pseudo-static rules, how do you handle the 404 error page that appears on the website?
A1:After configuring pseudo-static, if a 404 error occurs, first check the Nginx configuration file inproxy_passthe directive to ensure that it points to the correct IP address and port number (for examplehttp://127.0.0.1:8001) The address and port that your AnQiCMS application actually listens to are identical.Next, confirm that the AnQiCMS backend's 'pseudo-static rules' settings match the Nginx rules.For example, if the Nginx configuration expects an ID in the URL, but the AnQiCMS backend has selected the filename pattern, it may cause routing parsing to fail./www/wwwlogs/您的域名_error.logThey can provide more specific error information.
Q2: I have configured Nginx's pseudo-static, why does the website URL still look dynamic or not display in the format I want?
A2:The Nginx pseudo-static rules are mainly responsible for rewriting the pseudo-static URL of the browser request to the AnQiCMS application, but AnQiCMS itself also needs to generate the frontend display URL according to its backend configuration.Make sure you are logged in to the AnQiCMS backend, go to "Function Management" under "Static Rule", and select the static mode suitable for your needs (such as number mode, model naming mode, or custom mode).Only when both the Nginx and AnQiCMS rules are correctly configured and work together, the website's URL can be displayed correctly in pseudo-static form.
Q3: Can I make more complex customizations to Nginx's pseudo-static rules?
A3:Can. AnQiCMS provides a 'custom mode' in the 'pseudo-static rules' feature on the backend, where you can write specific URL rules according to your needs and use the system provided{id}/{filename}/{catname}/{module}Use variables to build URLs. These custom rules guide AnQiCMS in generating the corresponding links. At the same time, you can also configure the Nginx file in the Baota panel.location / { try_files ...; }Instructions to add more complexrewriterules to implement more advanced URL rewriting logic, but this requires you to know Nginx'srewriteHave a deep understanding of the module, and pay attention to testing to avoid introducing errors. It is recommended to back up the current Nginx configuration before making complex modifications.