AnQiCMS is an enterprise-level content management system developed based on the Go language, known for its high efficiency, security, and ease of deployment, and has gained the favor of an increasing number of small and medium-sized enterprises and content operation teams. After installing AnQiCMS via the command line in the Linux environment, we usually find that it runs by default in8001This specific port. To allow users to access through a more standardized80port (HTTP) or443Access the website directly via port (HTTPS), and better manage static resources, implement pseudo-static functions, configuring Nginx reverse proxy has become an indispensable step.

This article will serve as your experienced website operations expert, elaborating on how to install AnQiCMS via the command line, and then configure Nginx to set up reverse proxy so that it can pass through80Port access is smooth.


1. Understand the operation mechanism and the necessity of reverse proxy of AnQiCMS.

After you successfully install and start AnQiCMS via the command line, it actually runs as an independent application on the server, usually listening on a non-standard port, such as8001This means that if you enter the server IP address directly in the browser plus8001the port (such ashttp://your_server_ip:8001), you can access the AnQiCMS site.

However, in the actual operation of the website, we hope that users can directly access through the domain name, for examplehttp://www.yourdomain.comPort numbers are not required. This requires the introduction of a 'gatekeeper' - Nginx.Nginx plays the role of a reverse proxy server here.It will listen to the standard80port (or443The port is used for HTTPS requests, when the user initiates a request, Nginx receives the request and then forwards it to a running8001The AnQiCMS backend service on the port, then presenting the content returned by AnQiCMS to the user.

This architecture not only simplifies the user experience, but also has several important advantages:

  • Port standardization:Users do not need to remember specific port numbers.
  • Static resource optimization:Nginx can directly handle images, CSS, JavaScript, and other static files without needing to forward these requests to AnQiCMS, thus greatly reducing the load on AnQiCMS and improving the website's response speed.
  • Enhanced Security:Nginx can provide a layer of security protection in front of AnQiCMS, filtering malicious requests.
  • Load Balancing and Scalability:In theory, Nginx can distribute requests to multiple AnQiCMS instances, implementing load balancing and laying the foundation for future expansion.
  • SEO friendly:Through Nginx, you can implement more flexible pseudo-static (URL rewrite) rules, which is helpful for search engine optimization.

2. Preparatory work

Before starting the Nginx configuration, make sure you have completed the following steps:

  1. AnQiCMS has been installed and is running:Make sure you have successfully installed AnQiCMS according to the official AnQiCMS documentation via the command line on a Linux server, and the AnQiCMS process is running by default,8001The port (or any custom port) is running normally. You canps -ef | grep anqicmscheck its running status with the command.
  2. Nginx is installed:Your Linux server has Nginx Web server installed.
  3. Domain has been resolved:The domain name you plan to use to access AnQiCMS (for examplewww.yourdomain.com) has been correctly resolved to your server IP address.

Step 3: Configure the detailed steps of Nginx reverse proxy

Now, let's configure Nginx step by step to make it able to proxy AnQiCMS service.

1. Find the Nginx configuration file

The main configuration file of Nginx is usually located in/etc/nginx/nginx.conf. To better organize your site configuration, it is recommended to/etc/nginx/sites-available/Create a new configuration file for your AnQiCMS site in the directory, then enable it through a symbolic link/etc/nginx/sites-enabled/In the directory. Or, if your Nginx configuration allows, you can also directly in/etc/nginx/conf.d/Create in the directory.conffile.

We take in/etc/nginx/conf.d/Create a file namedyourdomain.com.conffile as an example.

2. Create or edit the site configuration file

Use your favorite text editor (such asviornano) to open or create the file:

sudo nano /etc/nginx/conf.d/yourdomain.com.conf

Then, paste the following configuration content in. Please replace it according to your actual situation.yourdomain.comand the installation path of AnQiCMS.

`nginx server {

# 监听80端口,用于HTTP访问
listen       80;
# 绑定您的域名,多个域名用空格隔开
server_name www.yourdomain.com yourdomain.com;
# 指定静态文件根目录。AnQiCMS 的静态资源(CSS, JS, 图片)位于其安装目录下的 public 文件夹
# 请将 /www/wwwroot/anqicms.com 替换为您的 AnQiCMS 实际安装路径
root /www/wwwroot/anqicms.com/public;

# 定义一个内部使用的 location 块,用于处理 AnQiCMS 的动态请求
# @AnqiCMS 是一个命名 location,Nginx 内部使用
location @AnqiCMS {
    # 将请求转发到 AnQiCMS 后端服务监听的地址和端口
    # 默认 AnQiCMS 监听在 127.0.0.1:8001
    proxy_pass http://127.0.0.1:8001;
    # 传递原始请求的 Host 头,确保 AnQiCMS 识别正确的域名
    proxy_set_header   Host             $host;
    # 传递客户端真实 IP 地址,便于 AnQiCMS 后台统计和日志记录
    proxy_set_header   X-Real-IP        $remote_addr;
    # 传递代理链中的所有 IP 地址
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    # 也可以添加其他常用的代理头,例如:
    # proxy_set_header   X-Forwarded-Proto $scheme; # 传递协议类型 (http/https)
}

# 当 Nginx 尝试查找文件时,如果遇到 404 错误,则将请求内部重定向到 @AnqiCMS 块处理
# 这对于 AnQiCMS 的伪静态路由至关重要,它能让 AnQiCMS 处理那些不对应实际静态文件的 URL
error_page 404 =200  @AnqiCMS;

# 根目录请求处理逻辑
location / {
   # 尝试查找请求的 URI 对应的静态文件
   # 尝试查找请求的 URI 对应的目录下的 index.html 文件
   # 如果上述都找不到,则将请求交给