Article Title: two key points of Apache server configuration in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The Apahce Server is a stable, commercial, and open-source HTTP server. It is dominant in the HTTP market. According to statistics from authoritative departments, the market share of Apache servers is about 60%, showing its market influence. Because Apache servers can provide standard platforms for HTTP communication protocols, they can help enterprises establish a stable WEB application environment in both commercial and experimental fields. I will not talk about it here. I will only talk about the two things that I think are important in the configuration of the Apache server.
1. Flexible application redirection.
Sometimes for some reason, such as adding a hard disk or upgrading a server, the system administrator needs to change the storage location of webpages on the WEB server. How can I let the WEB server know the change information? If you change the webpage location one by one, the workload is obviously too heavy. In some WEB servers, this problem is solved through relative paths. As long as you move the folder to another location, and then you only need to change the location of the root folder, the webpage content in this folder does not need to be adjusted one by one because of the relative path. However, the Apache server adopts another unique processing mechanism, namely, the redirection function.
When the client browser requests a webpage from the WEB server, the WEB server first finds the webpage pointed to by the URL address and then returns the webpage content to the browser. If the system administrator needs to move the WEB site webpage location, it is difficult to ensure that all connections directed to the old WEB page address are changed to the new location. In this case, the system administrator needs to test and adjust the connection to ensure the correctness of the connection. Obviously, this manual adjustment requires a lot of work, because there may be hundreds of connections in a certain webpage. Changing these connections one by one requires not a small amount of work. Even if the number is small, but the system administrator needs to manually modify the information, they are not willing to do it, because it is too challenging. For this reason, is there a one-time update method? In the database, you can use the Where statement to find the content to be updated and then use the Update statement to make one-time adjustments to the content to be updated. This is what is implemented on the Apache server. For example, you need to use the redirect old URL to add a new URL address in the Apache server command line environment. The old URL address of the first parameter is like a query condition. The record that meets the condition is searched out (other webpages direct to the address of the webpage) and replaced with the new URL address. When the client requests to access this webpage, the browser will return the new webpage content to the client. Note that the client sends a request using the old WEB address (the client does not know the modifications made in the server background). After the WEB server finds that the webpage location has changed, the client's webpage access request is redirected. Replace the old address sent by the client with the new address. This is the redirection mechanism adopted by the Apache server.
Using this redirection function not only solves the problem of webpage location change, but also has some other useful uses. For example, if you change the webpage or add a new function, you may need to suspend the user's access within a short period of time. For example, some forums may have to be temporarily suspended due to merging or hacking. To apologize to visitors, they often want to connect their access requests to a special page. This page shows the reason why the website is temporarily closed and the development time. After the visitor sees this information, the visitor can know that this is only temporarily closed, rather than permanently closed. This helps to stabilize the hearts of old customers and keep the accumulated customer groups intact. In fact, this can also be achieved through the redirection function. For example, the system administrator defines a webpage in advance and uses the redirection function to update the website address as needed. After the fault is restored, enable the original connection.
Therefore, the redirection function on the Apache server is very useful. It can be used not only to complete the relative path function on other servers, but also to complete what it does not have. If the Linux system administrator wants to use the Apache server to implement the enterprise's HTTP server, the redirection function is undoubtedly a required function.
Ii. cache settings.
The cache mentioned here is totally different from the express cache mentioned on other application servers. System Administrators cannot confuse the cache. The high-speed cache of other application servers usually refers to storing users' content in the memory. However, due to the limited memory capacity, not many contents are saved. However, because Web pages often contain a wealth of pictures, animations, background music, and other information, the memory alone often plays a limited role. Therefore, the Apache server implements a hard disk-based data cache technology. The cache on the Apache server refers to the information obtained from the last request of the client, such as the webpage content and images, stored in the server's hard disk (instead of memory ). When the client requests the same information next time, it can immediately respond to the client. In this way, the webpage response time can be greatly reduced, and the network application efficiency can be improved at a higher speed. Because the hard disk usually has no memory space limit, more content can be cached. The cache function of the Apache server mainly addresses the following issues.
1. Set the cache capacity. Although the disk space is relatively large, you must set a maximum ceiling for data cache. Otherwise, the server hard disk will be consumed by the data cache sooner or later. Therefore, after the data cache technology is enabled, the system administrator should not forget to immediately use the CacheSize parameter to set the upper limit of the cache. When the server checks the cache capacity, if the maximum limit is exceeded, the server will delete more than part of the content. Note that the unit of this parameter is KB. If you need this parameter to be cached at only 2 MB, you need to set this parameter value to 2048. How much should this value be set? There is no fixed standard. It depends on the content provided by the server. If the server contains a large number of animations, movies, and so on, it is best to set a large cache space. In this case, the more people access the same resource, the higher the access rate for subsequent visitors.
2. Check the data cache interval. The server regularly checks the data cache space. First, ensure that the data cache space is within the maximum limit; second, check whether the content in the data cache is updated in a timely manner. By default, the update time is determined by the CacheGcinterval parameter of the Apache server. The default value is 4 hours. You can change this value based on the purpose of the server. For example, if the server is a server that provides timely news, you need to set a smaller value. This parameter must be enabled when data caching is enabled. If this function is not enabled, the server will not check the content in the cache, and will not automatically delete the content that exceeds the maximum cache capacity. This will cause the disk space to be gradually consumed, until the direct path occupies the entire hard disk. When setting this parameter, you often need to choose between the hard disk space and the data validity. Sometimes the system administrator must constantly adjust and track to determine a reasonable parameter.
[NextPage]
In addition, this parameter is often used together with the CacheLastMoidffiedFaor parameter. As the name suggests, this parameter is mainly used to update files in the data cache space, but it is not a simple time parameter, but a time coefficient. On the Apache server, the expiration time in the cache file is calculated based on this coefficient. If a file in the data cache has been last modified for 30 hours, and this parameter is 0.1 (default), the expiration time is the product of the two values, that is, 3 hours. After three hours, the data cache file is automatically deleted (provided that the preceding data cache time interval parameter is enabled ). This can save data cache space and improve hard disk utilization. It can also ensure the effectiveness of information in the data cache.
3. Disable caching. Not all websites actually need this data cache. For websites that provide fund net worth or dynamic stock information, data caching is not required. Because the information of these websites is highly time-effective. Generally, websites with frequently changed content do not require data caching. If this technology is used, it is possible that the stone is lifted to hit your own feet. Therefore, if you need to disable this data cache, you can use the NoCahce command to disable this data cache function. If you use technologies such as virtual hosts on a server to implement multiple websites, you can also set them separately based on the purpose of the website. For example, you can disable caching for websites such as news or funds that provide timely information, and disable caching for other websites. You can even enable or disable data caching for specific webpages based on their addresses. Obviously, Apache data cache management is more flexible than other application servers.