When deploying AnQiCMS in a Linux command-line environment, configuring Nginx as a reverse proxy is a key step for website operation.AnQiCMS as a high-performance, scalable Go language content management system, usually runs on a non-standard port on the server.To enable users to access the website through standard HTTP (port 80) or HTTPS (port 443) and fully utilize the advantages of Nginx in static file serving, load balancing, and security, we need to carefully set up Nginx reverse proxy.

The core function of Nginx reverse proxy is to forward external requests to the internal AnQiCMS application, while handling static files, optimizing connections, and providing an additional layer of security protection.It masks the actual port of AnQiCMS, only exposing the standard web service port to the outside, making the entire architecture more robust and secure.

Prepare the basic environment before deploying AnQiCMS

Before we start configuring Nginx reverse proxy, we need to make sure that the server already has the Nginx service. Typically, in most Linux distributions, it can be installed through package managers such asaptoryum) Install Nginx easily. In addition, the AnQiCMS application itself also needs to be deployed and run.According to the official documentation of AnQiCMS, it usually listens to an internal port as a Go language application, such as the default one8001Port. This means that the AnQiCMS executable file is already running on the server before the Nginx configuration, and it can be accessed locally127.0.0.1:8001Access.

The deployment process of AnQiCMS usually includes downloading the Linux installation package from the official website, unpacking it to a specified directory, such as/www/wwwroot/anqicms.com. Then, by executingstart.shScript to start the AnQiCMS service, the script will startanqicmsThe main program, making it listen on the configured port. This port is the target of Nginx's reverse proxy.At the same time, AnQiCMS static resource files (such as CSS, JavaScript, and images) will be stored in the directory where it is installed.publicIn the folder, Nginx needs to be configured to directly serve these static resources to improve access efficiency.

Nginx reverse proxy configuration example

Here is a detailed Nginxserverblock configuration example, used towww.yourdomain.comAll requests under the domain are reverse proxied to the locally running AnQiCMS application and static files are handled first:

`nginx server {

# Nginx监听的端口,通常为HTTP的80端口
listen 80;

# 您的网站域名,可以同时包含PC端和移动端域名
server_name www.yourdomain.com yourdomain.com; # 示例:www.anqicms.com m.anqicms.com

# 网站的静态文件根目录。这应该指向您的AnQiCMS安装目录下的 public 文件夹。
# Nginx会先尝试在这里查找请求的静态文件。
root /www/wwwroot/anqicms.com/public;

# 定义一个命名location,专门用于将请求代理到AnQiCMS应用。
# 当 try_files 无法找到匹配的静态文件时,请求会被转发到这里。
location @AnqiCMS {
    # 将请求转发到AnQiCMS应用监听的地址和端口。
    # 127.0.0.1 是本地回环地址,8001 是AnQiCMS默认监听的端口。
    proxy_pass http://127.0.0.1:8001;