When deploying AnQiCMS with Baota panel, which folder should the Nginx running directory be configured to?

Calendar 👁️ 67

As an experienced website operations expert, I am happy to provide you with a detailed explanation of the correct configuration method for the Nginx running directory when deploying AnQiCMS using the Baota panel, and to deeply analyze the principles behind it, ensuring that you not only know the what but also the why.


When deploying AnQiCMS using Baota panel, which directory should the Nginx running directory be configured to? Deep analysis and practice

When deploying AnQiCMS such a Go language application using the Baota panel, many operators may be accustomed to directly pointing the Nginx running directory to the root directory of the project.However, for AnQiCMS, the Nginx running directory has specific **practices, which are crucial for the performance, security, and normal operation of the website.

The answer is: The Nginx running directory should be configured to your AnQiCMS project directory.publicFolder.

Now, let's take a detailed look at why it is.publicFolder, as well as how to configure such settings in the Baota panel.

Understand the collaboration mode between AnQiCMS and Nginx.

AnQiCMS is an enterprise-level content management system developed based on the Go language, with core features of high performance and easy deployment.Different from traditional PHP applications (such as WordPress), Go applications usually include a high-performance web server that can directly handle HTTP requests.In this architecture, Nginx plays the role mainlyReverse Proxy (Reverse Proxy)andStatic File Server (Static File Server).

  1. Reverse Proxy: Nginx receives all user requests and forwards dynamic content requests to the Go application running within AnQiCMS itself (usually listening on port 8001).
  2. Static Resource Service: The CSS, JavaScript, images, and other static files of AnQiCMS are stored in the project directory by default.publicIn the folder. To improve the loading speed of the website and alleviate the pressure on the backend Go application, we usually let Nginx directly handle the requests for these static files, rather than forwarding them to the Go application each time.Nginx performs exceptionally well in handling static files, its efficiency is much higher than having the backend application distribute them.

Based on such a collaboration mode, set the Nginx running directory topublicfolder, and cooperate with specific rewrite rules to achieve ** performance and functionality.

Practice of Nginx configuration in Baota panel

The process is roughly as follows when you create a site and configure Nginx for AnQiCMS in the Baota panel:

First, you need to unzip the AnQiCMS installation package to a directory on the server, for example/www/wwwroot/yourdomain.com. In this directory, you will see a file namedpublic.

Next, when creating a new website in the Baota panel, you can choose 'static' or not create a database (because AnQiCMS will connect to the database automatically). The key is the Nginx configuration:

  1. Set website directory In the "Website Directory" tab of the website settings, you need to set the "Running Directory"precisely to the AnQiCMS project directory under yourpublicFolderFor example, if the root directory of your AnQiCMS project is/www/wwwroot/yourdomain.comthen the runtime directory should be set to/www/wwwroot/yourdomain.com/publicSo, Nginx will first check this directorypublicLocate the requested file in the directory.

  2. Configure Nginx's pseudo-static rules: It is not enough to just set the running directory. Since AnQiCMS is a Go application, its dynamic requests need to be forwarded to the Go program itself.Therefore, you also need to add reverse proxy rules in the "virtual static" configuration of Nginx.Recommended Nginx pseudo-static rules by AnQiCMS (usually ininstall.mdorstart.mdAs provided in the document) as follows:

    location @AnqiCMS {
        proxy_pass https://en.anqicms.com; # 这里是AnQiCMS应用监听的端口,默认为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; # 如果找不到文件,将请求重写到AnqiCMS处理
    location / {
       try_files $uri $uri/index.html @AnqiCMS; # 核心:优先尝试静态文件,否则转发给AnqiCMS
    }
    

    This rule'slocation /Paragraph is crucial.try_files $uri $uri/index.html @AnqiCMS;Means:

    • Nginx will first try to locate in/www/wwwroot/yourdomain.com/public(which is the runtime directory you set) to find the file requested by the user ($uri). If found, it will return directly, which greatly accelerates the loading of static resources.
    • If not found$uriit will try to find$uri/index.html(for example, if the request/aboutit will try to find/public/about/index.html)
    • If these are not found, Nginx will forward the request@AnqiCMSThis internal naming rule forwards to the AnQiCMS application running in the backgroundproxy_pass https://en.anqicms.com;) handled by Go application for dynamic routing and content generation.

    By such configuration, Nginx can efficiently serve static content and seamlessly pass dynamic content requests to AnQiCMS, ensuring the website is both fast and stable.

Considerations for multi-site deployment

If you plan to deploy multiple AnQiCMS sites on a single server, this principle also applies.Each AnQiCMS instance (if not installed through the built-in multi-site feature of AnQiCMS, but independently installed) requires a separate port and Nginx configuration.The Nginx running directory of each site should still point to the respective project directory belowpublicFolder, and configure the corresponding pseudo-static reverse proxy rules, justproxy_passThe port to which it points may change depending on the listening port of your AnQiCMS instance.

Summary

Properly configuring the Nginx runtime directory is a key step in the successful deployment of AnQiCMS. Point it to the root directory of the project.publicfolder, with precisetry_filesandproxy_passThe rule can maximize the use of Nginx's static file service advantages and the efficient processing capabilities of Go applications, providing your website with excellent performance and user experience.When operating the Baota panel, be sure to carefully check these configurations to avoid unnecessary running problems.


Frequently Asked Questions (FAQ)

  1. Why can't the Nginx runtime directory be directly set to the root directory of the AnQiCMS project?Answer: If the Nginx runtime directory is directly pointed to the project root directory, Nginx will attempt to directly provide all files under the project root directory, which may expose sensitive information such as code files, configuration files, and so on that should not be publicly disclosed, posing a security risk. At the same time, since the Go application itself handles dynamic requests, Nginx also needs to be configured with reverse proxy to forward requests to the Go application. Directly pointing to the project root directory will cause Nginx to be unable to effectively distinguish between static files and dynamic requests, thus makingtry_filesRules are difficult to effectively function, and may instead lead to resource loading errors or security vulnerabilities. The execution directory should be specified accurately topublicThe folder ensures that only static resources meticulously prepared by AnQiCMS are provided directly by Nginx, while the remaining dynamic requests are handled by the Go application, achieving a balance of security and performance.

  2. In Nginx configurationtry_filesWhat role does the command play here?Answer:try_files $uri $uri/index.html @AnqiCMS;It is a very powerful directive in Nginx configuration that defines the priority order of Nginx handling requests.

    • $uri: Nginx will first try to find the file that matches the request URI in the running directory you have configured (i.e./publicfolder). If the user requests/css/style.css, Nginx will try to locate/public/css/style.css.
    • $uri/index.htmlIf the first attempt fails, Nginx will then try to find in the subdirectory corresponding to the URIindex.htmlfile. For example, if the request/about/, Nginx will try to locate/public/about/index.html.
    • @AnqiCMSIf both of these attempts fail, it means that the request is not a static file or the corresponding default file cannot be found, then Nginx will pass the request to the one namedAnqiCMSThis block processes the internal naming Location block, which will pass throughproxy_passThe instruction forwards the request to the Go application running in the background. In short,try_filesEnsured that Nginx can serve static resources with priority and efficiency, only forwarding requests to dynamic applications when static resources are not found, thereby optimizing website performance.
  3. How should I modify the Nginx configuration if my AnQiCMS application does not listen on port 8001?Answer: AnQiCMS listens on port 8001 by default, but you may have changed this port in some cases (for example, inconfig.jsonMake changes)。If your AnQiCMS application is actually listening on a different port (such as 8002), then you need to modify the pseudo-static configuration in Nginx.proxy_passInstruction, point it to the correct port. Specifically, set `proxy_passhttp://127.0.0.1:

Related articles

How to view the root directory path of the AnQiCMS container in Docker environment?

When deploying AnQiCMS with Docker, you may sometimes encounter situations where you need to explore its internal file structure, such as locating the actual root directory path of the website.This is very important for troubleshooting file access issues, performing manual file modifications, or deeply understanding the operation mechanism of AnQiCMS within the container.As a website operations expert, I fully understand the value of this exploration. Next, let's unveil the 'mysterious veil' of the root directory of the AnQiCMS container website.

2025-11-06

What is the actual file path represented by variables like `{filename}` or `{catname}` in static rules?

## Unveiling the 'mysterious code' in AnQi CMS static rules: the truth about `{filename}` and `{catname}` As an experienced website operations expert, I am well aware that a friendly and efficient URL structure is crucial for a website's search engine optimization (SEO) and user experience.AnQiCMS (AnQiCMS) provides strong support in this aspect, especially its flexible static rule management function.However, when configuring these rules

2025-11-06

How should mobile template files be organized and stored when making a mobile phone template?

As an experienced website operations expert, I know how important it is to have a good mobile website experience in today's mobile internet age.Users are accustomed to browsing content on various mobile devices. If your website does not display well on mobile phones, it will not only lose users but will also affect the search engine rankings.AnQiCMS (AnQiCMS) is an efficient and customizable content management system that also provides clear and flexible solutions for mobile template design.Today, let's delve into it in detail when making mobile templates with Anqi CMS

2025-11-06

Where should the AnQiCMS single-page custom template files be stored?

In the daily operation of AnQiCMS (AnQiCMS), we often need to customize the website pages to meet specific design or functional requirements.A single page, such as 'About Us', 'Contact Us', etc., often carries unique brand information of the company, and therefore, configuring a custom template is a common need for website operators.Where should these single-page template files that carry creativity and customization be stored in the Anqi CMS directory?Today, let's delve deeply into this issue. ###

2025-11-06

How to view the storage path of AnQiCMS log files to troubleshoot program errors?

As an experienced website operations expert, I know that log files play a crucial role behind the stable operation of the system.When your AnQiCMS website encounters a program error, the log file is like a clue in a detective's hands, which can help us trace the cause and specific details of the problem.AnQiCMS is an enterprise-level content management system developed based on the Go language, with a simple and efficient logging mechanism. Understanding the storage path and viewing method of the log files is the first step in troubleshooting program errors and ensuring the healthy operation of the website.

2025-11-06

How to distinguish the file path of `config.` for different sites in multi-site configuration?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system, and its multi-site management function is undoubtedly a highlight favored by many operators.However, when it comes to multi-site configuration, some seemingly basic details, such as how to differentiate the `config.` file paths of different sites, often raise questions among users.Today, let's delve into this topic in depth to help everyone clearly understand the configuration logic of AnQiCMS under multi-site architecture.

2025-11-06

Where is the actual storage path of these image resources after I upload them to the background?

As an experienced website operation expert, I know the importance of image resource management for website performance, SEO, and even user experience.AnQiCMS (AnQiCMS) has made many meticulous designs in this aspect, allowing content operators to manage these valuable visual assets more efficiently.Today, let's delve deeply into a question that concerns everyone: 'Where are the actual storage paths of the image resources after I upload them to the backend?'}]

2025-11-06

How to set up the background to view or modify the specific URL address of the website logo image?

As an experienced website operations expert, I am well aware of the importance of the website logo to the brand image.It is not only the 'front door' of the website, but also a key element for users to identify your brand.In a powerful content management system like AnQiCMS, managing the website logo image address is a fundamental and frequent operation.Today, let's delve into how to easily view or modify the specific URL address of the website logo image through backend settings.

2025-11-06