In the daily operation and maintenance of Anqi CMS, we often deal with various configuration files. Among them,config.jsonThe file is undoubtedly one of the 'lifebloods' of AnQiCMS, carrying the core parameters for system startup. Today, as a veteran who has been deeply involved in website operations for many years, I will delve into this with everyone.config.jsonConfiguration of ports in the file and its inextricable connection with the start and stop of AnQiCMS service.
The 'lifeline' of AnQiCMS operation: config.jsonThe port configuration in the context
In the world of AnQiCMS,config.jsonThe file is the starting point of the "identity" and "code of conduct" for each site instance. It defines key information such as database connections, cache settings, and the most fundamental and directly impacting factor for service startup is the embedded port (portConfiguration.
Generally, in the root directory where you install AnQiCMS, you will find a file like this.config.jsonFile. Open it, and you will find a field named.portThe default value is usually.8001.This number is not arbitrarily set; it specifies the specific 'address number' that AnQiCMS service listens for external connections on your server.Imagine that your server is a building, AnQiCMS is a shop inside the building, and this port number is the only entrance that this shop is open to the public.All requests that want to access this AnQiCMS site must be received and processed by AnQiCMS service through this specified port.
Port association with AnQiCMS service 'breath': start and stop
This port number may seem simple, but it has a direct and profound connection with the 'breath' (i.e., start and stop) of AnQiCMS service.
When starting the service: Listening on the port
When you start the AnQiCMS service, whether by executingstart.shScript, or start the “Go project” in the Baota panel or other visual tools, the first operation of AnQiCMS program is to try to “occupy” andconfig.jsonConfigured in that port.If everything goes well, AnQiCMS will successfully bind to the port and start listening for requests from the client (such as a browser).At this moment, this port is like the only 'window' opened by AnQiCMS to the outside world, ready to receive and process all HTTP traffic.
However, if this port is already occupied by another program on the server (possibly another AnQiCMS instance, or another Web service), AnQiCMS service will fail to start.The system will throw an error message saying "The port is already occupiedThis requires us to timely investigate and resolve port conflict issues to ensure that each AnQiCMS instance has its exclusive 'door number'.
When stopping the service: the 'release' of the port.
When you decide to stop AnQiCMS service, whether by executingstop.shscripts, or by ending it in the Windows Task Manageranqicms.exeProcess, the system will attempt to shut down AnQiCMS program gracefully.Under normal stopping conditions, AnQiCMS will 'release' the ports it has previously occupied.This means that this port is now idle and can be used by other programs, or it can be reoccupied by itself when AnQiCMS starts up next time.
An "clean" stop process is crucial.If the AnQiCMS service terminates abnormally for some reason (such as a sudden power outage or being forcefully killed with 'kill -9'), it may not have a chance to release the port normally.Although programs developed in the Go language can usually handle such situations well, theoretically, a port unexpectedly occupied may be in the "TIME_WAIT" state for a short period of time, which may cause AnQiCMS or other services to be unable to use the port immediately within a short period of time, thereby affecting the rapid recovery of the service.Therefore, following the official provided startup/shutdown script, performing an elegant shutdown is the**practice**to ensure the smooth release of ports and stable operation of the system.
端口配置的实际应用:多站点与反向代理的艺术
Understood the correlation between ports and service startup/stop, we can better utilize this mechanism for more advanced deployment and operation strategies.
Single server multi-site deployment: Port is crucial
AnQiCMS's one major feature is the support for multi-site management.Imagine that you need to manage multiple content sites on the same server, each running independently.8001The port is not enough. In order for each AnQiCMS instance to work independently, you need to prepare an independent AnQiCMS program file (or logically independent running environment) for each instance on the server, and modify the root directory under each instance's directory.config.jsonfile,will their respectiveportthe parameters be set to different port numbers,such as8001/8002/8003English. Thus, each AnQiCMS site can run on its own independent 'address number' without interfering with each other.
Reverse proxy: the 'behind-the-scenes hero' of ports.
However, allowing users to directlyhttp://您的域名:8001This way of accessing the website is not common in actual production environments and is not professional enough.This is where reverse proxy (such as Nginx, Apache) becomes an indispensable 'behind-the-scenes hero'.
Reverse proxy servers listen to standard HTTP (port 80) or HTTPS (port 443), and when users access, the request first reaches the reverse proxy. The reverse proxy then forwards the request to the backend AnQiCMS service that listens on a non-standard port (such as127.0.0.1:8001).
This deployment method has many advantages:
- Standardized access: Users do not need to remember non-standard port numbers.
- Security enhanced:Hide the real port of AnQiCMS service to reduce the direct attack surface.
- SSL/TLS EncryptionEnglish: Reverse proxy can handle SSL certificates uniformly and implement HTTPS access, while AnQiCMS itself does not need to be configured directly.
- English: Load balancingIf multiple AnQiCMS instances are deployed, the reverse proxy can distribute traffic to achieve load balancing.
- Multi-site reuseOn a single 80/443 port, Nginx can distribute requests to different AnQiCMS instances (i.e., different internal ports) based on the domain name.
Therefore, in a multi-site deployment, you will see that each AnQiCMS instance is configured with a unique internal port, and all external traffic is intelligently routed to the correct internal port through a reverse proxy, ultimately presented to the user.
Summary
config.jsonThe port configuration is the core element for the start, run, and stop of AnQiCMS.It not only determines how AnQiCMS service listens to and responds to network requests, but also plays a crucial role in multi-site deployment and reverse proxy architecture.Deeply understand this configuration and its association with the service lifecycle, which can help us operate and manage the AnQiCMS website more efficiently and safely, providing users with a smooth and stable access experience.
Common Questions (FAQ)
Q: How to deal with the prompt “Port is already in use” on the server?A: When you encounter the error “Port is already in use” while trying to start AnQiCMS, it usually means that you
config.jsonThe port configured has been occupied by another process on the server (it may be another AnQiCMS instance, or other web services, databases, etc.). Under Linux systems, you can uselsof -i:{端口号}Command to check which process is using the port (for examplelsof -i:8001)。After finding the PID (Process ID) of the process using the port,kill -9 {PID}Force the process to terminate. After termination, you can try to restart the AnQiCMS service. Under Windows, you can find it in the Task Manager.anqicms.exeProcess and end it, or check if there are other applications using the port. Make sure that the required ports of AnQiCMS are exclusive every time AnQiCMS starts.Q: How to modify the default port of AnQiCMS after installation?A: Modifying the running port of AnQiCMS is very simple. You just need to find the AnQiCMS installation directory under
config.jsonfile, open it with a text editor. Find the"port": 8001This line, will8001Modify it to the other port number you want to use (for example8002)。After modifying and saving the file, please make sure to stop the currently running AnQiCMS service first, and then restart it. The new port configuration will take effect only after that.proxy_passThe port number in the target address should also be changed to the new value, otherwise users will not be able to access the website normally.Q: Why do we still need to set up a reverse proxy if AnQiCMS has its own port?A: It is recommended to use a reverse proxy (such as Nginx, Apache) to forward access to AnQiCMS in a production environment, as it brings various benefits:
- Standardized Port AccessUsers are accustomed to using standard 80 (HTTP) or 443 (HTTPS)