AnQiCMS is an enterprise-level content management system developed based on the Go language, which has been favored by an increasing number of small and medium-sized enterprises and content operation teams due to its high efficiency, security, and ease of deployment. After installing AnQiCMS via the command line in the Linux environment, we usually find that it runs by default on8001This specific port. To allow users to use it more standardly80port (HTTP) or443Directly access the website via port (HTTPS), and better manage static resources, realize pseudo-static features, configuring Nginx reverse proxy becomes an indispensable step.
This article will serve as your experienced website operations expert, elaborating on how to install AnQiCMS via the command line and configure reverse proxy with Nginx, so that it can be accessed through80Port smooth access.
1. Understand the operation mechanism of AnQiCMS and the necessity of reverse proxy.
After you successfully install and start AnQiCMS via command line, it actually runs as an independent application on the server, usually listening on a non-standard port such as8001This means, if you enter the server IP address plus8001port (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 access it directly through the domain name, for examplehttp://www.yourdomain.comWhile no additional port number is required.This requires the introduction of a 'goalkeeper'—Nginx.Nginx plays the role of a 'reverse proxy server' here.80port (or443Port used for HTTPS requests), when the user initiates a request, Nginx receives the request and then forwards it to the running8001The AnQiCMS backend service of the port, and then present the content returned by AnQiCMS to the user.
This architecture not only simplifies the user experience, but also has the following 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, thereby greatly reducing the load on AnQiCMS and improving the website's response speed.
- Security enhancement:Nginx can provide a layer of security protection for the AnQiCMS front-end, filtering malicious requests.
- Load balancing and scalability:Theoretically, Nginx can distribute requests to multiple AnQiCMS instances, achieving load balancing and laying the foundation for future expansion.
- SEO friendly:Through Nginx, more flexible pseudo-static (URL rewrite) rules can be implemented, which is helpful for search engine optimization.
Second, preliminary preparation work
Before starting the Nginx configuration, please make sure you have completed the following steps:
- AnQiCMS has been installed and is running:Ensure that you have successfully installed AnQiCMS on a Linux server according to the official AnQiCMS documentation via the command line, and that the AnQiCMS process is running by default,
8001Port (or any custom port) is running normally. You can check its status with the command.ps -ef | grep anqicmsCommand to view its running status. - Nginx is installed:Your Linux server has Nginx Web server installed.
- The domain has been resolved:You plan to use the domain name for accessing AnQiCMS (for example
www.yourdomain.com) has been correctly resolved to your server IP address.
三、Configure Nginx Reverse Proxy Detailed Steps
Now, let's step by step configure Nginx to make it able to proxy AnQiCMS service.
1. Find the Nginx configuration file
The main configuration file of Nginx is usually located at/etc/nginx/nginx.conf. It is recommended to organize your site configuration better/etc/nginx/sites-available/Create a new configuration file under the directory for your AnQiCMS site, and then enable it via a symbolic link./etc/nginx/sites-enabled/Directory. Or, if your Nginx configuration allows, you can also directly in/etc/nginx/conf.d/directory create.conffile.
We take/etc/nginx/conf.d/in the directoryyourdomain.com.conffile as an example.
2. Create or edit the site configuration file
Use your favorite text editor (such as)viornano打开或创建该文件:
sudo nano /etc/nginx/conf.d/yourdomain.com.conf
然后,将以下配置内容粘贴进去。请务必根据您的实际情况替换yourdomain.com和 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 文件
# 如果上述都找不到,则将请求交给