Discuz! NT static File Cache (SQUID)

Source: Internet
Author: User

In the latest version of the product, we provide a solution for caching static files, that is, using squid as the static front-end, deploy most of the static files in the forum or link them to a new HTTP link. The static files that can link the external links include:

 

1. All JS files with 'template _ 'headers and some JS files in this folder under discuz. Web/JavaScript.
2. All CSS or image files in the template folder (excluding space album folders)
3. All files under the Medal (MEDAL) and topicidentify (subject identification icon) in the foreground image folder.

 

At the same time, in the latest product, we addedEntlib. configFile (located in the discuz. web \ config \ folder), used to configure all and discuz! The configuration information related to the NT Enterprise Edition, the HTTP external link address mentioned above, has the corresponding configuration in this file. We only need to edit the corresponding node information to enable this function, for example, the following Configuration:

 

<? XML version = "1.0"?>
<Entlibconfiginfo xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.w3.org/2001/XMLSchema">
<Medaldir> http: // 10.0.8.12: 81/myimage/medals/</medaldir> <! -- Medal -->
<Topicidentifydir> http: // 10.0.8.12: 81/myimage/identify/</topicidentifydir> <! -- Topic authentication icon -->
<Jsdir> http: // 10.0.8.12: 81/JavaScript/</jsdir> <! -- JS path in the Javascript/directory -->
</Entlibconfiginfo>

With the above file configuration, you can direct the external links of the static files 1 and 3 mentioned above to other addresses. Of course, if you want to set the CSS and image files in the template folder, we also need to set them in the template list in the management background. For convenience, I directly write the static template file external link information in the dnt_templates table (default) in the database, such:

 

Currently, our product supports setting different static file external link addresses for different templates, such.

In this way, after setting the above content, we can see in the source code of the IE page that the current static file has been linked to a new address, such as (showforum. ASPX page ):


 

Of course, the program development and configuration have been completed. The following describes how to configure squid to enable static front-end services in architecture.

 

Currently, squid has two platform versions: Linux and Windows. Our products support squid programs on this platform. To facilitate deployment, we will only introduce the installation steps on the Windows platform (there are a wide range of documents for installing squid in Linux on the Internet ).

 

First, download the corresponding squid Windows version to the local device from the address below.

Http://squid.acmeconsulting.it/

 

Decompress the file to the directory of drive C and run the following command under the squid \ etc directory:

1. Copy squid. conf. Default and rename it Squid. conf.
2. Copy cachemgr. conf. Default and rename it as cachemgr. conf.
3. Copy mime. conf. Default and rename it mime. conf.

Configure squid. conf and related nodes. The following is an introduction:

# Enable port 81 of the current host as the squid service port
Http_port 81 vhost


# Host name displayed on the browser
Visible_hostname cache. discuznt

 

Because Squid supports cluster deployment, it provides the corresponding configuration node, namely cache_peer. For more information, see this link. Here, I will describe the deployment environment. In the server environment of my department, I will take out two machines as the sibling (sister) neighbors.

Squid operation mode:
1. When the squid server does not have any data, it will first ask the squid server of sibling for data. If sibling does not have any data, skip it and ask the parent directly.
2. Ask the parent for information, and wait until the parent gives it the information (parent's own information or get it on the Internet ).
3. If no parent exists, go to get on the Internet.
4. If neither of the three methods can obtain the required information, the user can return the information to the user.

Here, I deploy the static file of the corresponding product to the 10.0.8.12 machine and configure an IIS Site with port 7001. (Note: This step can be omitted in the actual environment, configure the site information cached by squid to its squid. CONF file ). In this way, the node information is as follows:

# Configure cache nodes
Cache_peer 10.0.8.12 parent 7001 0 no-query no-digest originserver name =
#10.0.8.13 is a (sister) neighbor
Cache_peer 10.0.8.13 sibling 81 3130 proxy-only name = B

 

Copy the above settings to the corresponding node of squid running on port 81 on the machine 10.0.8.14.
 
The following describes the configuration of squid. conf on 10.0.8.12.

Hierarchy_stoplist cgi-bin? \. Aspx \. html
ACL query urlpath_regex cgi-bin \? \. Aspx \. html
Cache deny Query
Via on

 

The preceding configuration information is described as follows:
Squid internally marks each client request as cascade or not cascade. Requests that cannot be stacked do not seem to cause cache hits. For example, the POST request response is almost never cached. When squid can easily connect to the original server, it is a waste of resources to forward requests that cannot be cached to the neighbor cache. Some rules that distinguish between cascade and non-cascade requests are difficult to encode in Squid. For example, the post and put methods cannot always be stacked. However, the hierarchy_stoplist command allows you to customize this algorithm. It contains a string list. When they are found in the URI, squid marks the request as not cascade. The default list is:
Hierarchy_stoplist? In this case, any request containing a question mark or cgi-bin string matches the list and becomes non-stacked.
By default, squid directly sends non-cascade requests to the original server.

It can be understood as not caching or querying requests with a specified extension and link string containing specific characters. Request pages such as aspx.html are directly forwarded to the original server ).

 

The following information is used for configuration in the production environment.

# Cache_peer_domain a parent ***. com http: // www. ***. COM/BBS. ***. com home. ***. com PMA. ***. com
# Cache_peer_domain B parent. com. net. org. CC. TV. cn. biz. Name


Note: The cache_peer_domain command is an early form of the cache_peer_access command. Compared with the full access control feature, it only uses the domain name in the URI. It is often used to distinguish a group of parent caches by domain names. For example, if you have an intranet all over the world, you may want to send requests to the cache in their respective continents:

# Set different domain names to be forwarded to different cache_peer. If this is not the case, different domain name requests may be distributed to the same server.
ACL all SRC 0.0.0.0/0.0.0.0

# Cache file directory and directory format:
Cache_dir ufs c:/squid/var/cache 256 16 256

# ICP is a lightweight target location protocol that was invented as part of the harvest project. An ICP customer sends a query message to one or more ICP servers and asks if they have cached a URI. Each server responds to an icp_hit (ICP hit), icp_miss (ICP lost), or other types of ICP messages. The ICP customer uses the information in the ICP response to make the forwarding decision. In addition to indicating cache hits, ICP also provides clues about the network conditions between squid and the neighboring cache. When the icp_port command is used, squid automatically becomes the ICP server.
Icp_port 3130
Icp_access allow all
Http_access allow all

 

Defines the access list to the neighbor cache. That is to say, it determines which request is allowed or not allowed to be sent to the neighbor cache. See this link.

Cache_peer_access A allow all

# The following code is used as the path for saving the error message.
# Error_directory C:/squid/usr/local/squid/share/errors/simplify_chinese

# Because the current Internet Explorer is multi-threaded, long links are closed considering the consumption of network resources such as server bandwidth.
Client_persistent_connections off

# The server persistent link is used to use an opened socket link when the server transmits a message to save resources.
Server_persistent_connections on

# Enable the memory pool and configure the size
Memory_pools on
Memory_pools_limit 768 MB

# Display the client's intranet IP Address
Forwarded_for on

# Disable Client statistics
Client_db off

# Access logs. in the production environment, this file needs to be split.
Access_log C:/squid/var/logs/squid/access. Log

# Cache logs. in the production environment, this file needs to be split.
Cache_log C:/squid/var/logs/squid/cache. Log

Note: The c: \ squid \ sbin \ squid.exe. log file is also very important. It is the squid startup log. When an application encounters a problem, you can find some problems.

After the information is configured, run cd in the command line window to the C: \ squid \ sbin directory and run

C: \ squid \ sbin \> squid-I-n dnt_squid (Note: Use squid-r-N dnt_squid to delete the service with the specified name)
C: \ squid \ sbin \> squid-z

In this way, the squid service is installed on the machine. Start the Service as follows:

C: \ squid \ sbin \> Net start dnt_squid (Service name defined above) Note: stop the service. net stop dnt_squid

 

In this case, access the squid server on IE:

Http: // 10.0.8.12: 81/(your squid Server IP address). Then, squid forwards the request to http: // 10.0.8.12: 7001/(the web server address created in IIS)

The squid is also installed and configured on 10.0.8.14. However, you need to configure the squid on the cache_peer node.

Of course, the squid cached files are basically, that is, a JS file will generate a cache file, and the size and size remain unchanged, but if it is an image file, the cached files generated by squid cannot be opened by the image View software, but text files do not have this problem.

Note: The squid official site has detailed configuration information. The configuration content described in this article can be used as a reference for getting started.

Click here to download the final configuration file (SQUID. conf file in the compressed package ). In addition, I used LoadRunner locally to test concurrent user 1000 (v_user). The results are good. Click here for the report.


At the same time, squid also provides a client tool named squidclient (in c: \ squid \ bin) that is very useful, such as getting some system information during squid runtime:

Squidclient-P 81 Mgr: info # squid running status information
Squidclient-P 81 Mgr: Mem # squid memory usage
Squidclient-P 81 Mgr: Objects # list of cached quid
Squidclient-P 80 Mgr: diskd # disk usage of squid

Of course, the most commonly used is the purge command, which forcibly updates the cache information of a URL, as shown in

Squidclient-P 81-M purge http: // 10.0.8.12/: 81/CSS/dnt.css

For more information, run the HELP command:

Squidclient-H

 

Discuz! NT static File Cache (SQUID)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.