Nginx 1.0.0 with Ngx_cache_purge to realize efficient reverse proxy _nginx

Source: Internet
Author: User
Functionally, Nginx already has the Web cache Acceleration feature squid has, and the ability to clear the specified URL cache. But in the performance, Nginx to multi-core CPU's utilization, surpasses squid many. In addition, Nginx is much more powerful than squid in reverse proxies, load balancing, health checks, back-end server failover, rewrite rewriting, and ease of use. This allows a nginx to be used both as a load-balancing server and as a Web cache server. --by Banquet

Download the latest version of the 2011-05-03 update 1.3
wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz
Tar zxf ngx_cache_purge-1.3.tar.gz

Switch to Nginx directory
CD nginx-1.0.0
./configure--user=www--group=www--add-module=. /ngx_cache_purge-1.3--prefix=/usr/local/webserver/nginx--with-http_stub_status_module
Make;make Install

Installation Complete!

After installation, under the/usr/local/webserver/nginx four more directories, respectively, are fastcgi_temp,proxy_temp,scgi_temp and uwsgi_temp.

Proxy_temp this directory to store temporary files, you need to see whether the WWW has permission to write, if not writable, can not generate files in this directory, will cause reverse proxy failure. You can also set Proxy_temp_path to specify the directory where temporary files are stored in the Nginx configuration.

Nginx Configuration File Reference:

HTTP {
#proxy_temp_path/www/proxy_temp;
#设置Web缓存区名称为cache_one, the memory cache space size is 100mb,1 Day has not been accessed automatically clear, hard disk cache space size of 10GB.
Proxy_cache_path/www/proxy_cache levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=10g;

server {
Listen 80;
server_name s.jb51.net;

Location/{
Proxy_cache Cache_one;
Proxy_cache_valid 304 12h;
Proxy_cache_key $uri $is_args$args;
Proxy_set_header Host $host;
Proxy_set_header x-forwarded-for $remote _addr;
Proxy_pass http://www.jb51.net;
Expires 1d;
}

Location ~/purge (/.*) {
Allow all;
Allow 127.0.0.1;
# Deny All;
Proxy_cache_purge Cache_one $1$is_args$args;
}
Access_log/www/logs/s.log access;
}
......
}

Thus accessing s.jb51.net/images/logo.gif, the reverse proxy will go to request Http://www.jb51.net/images/logo.gif, save in memory, and then output.
If logo.gif This file has changed, you need to refresh the cache, Access S.jb51.net/purge/images/logo.gif, you will be prompted: successful purge

Key:/images/logo.gif
Path:/www/proxy_cache/39aaa70038997e0e5e77beaa4392848d
If this file is not cached, prompt: 404 Not Found

If you have already installed Nginx, please be sure to use Nginx-s reload reboot is not valid! Be sure to start after the-s stop to use the new version of nginx!

I didn't notice it today, it took n hours on it!

/usr/local/webserver/nginx/sbin/nginx-v
Nginx:nginx version:nginx/1.0.0
Nginx:built by GCC 4.1.2 20080704 (Red Hat 4.1.2-46)
Nginx:configure arguments:--user=www--group=www--add-module=. /ngx_cache_purge-1.3--prefix=/usr/local/webserver/nginx--with-http_stub_status_module

Always thought it was a success, but repeated tests are clear failure, very depressed! Obviously opened the access log, the log does not record any information!
In the evening to continue the test, in the Nginx_error.log see the following error tips:
2011/05/11 21:23:40 [Emerg] 20976#0:unknown directive "Proxy_cache_purge" in/usr/local/webserver/nginx/conf/ nginx.conf:481
To confirm that this module is not installed, of course, can not be used. Later in a forum to see a person's reply said to restart, but reload is invalid. Just think of the previous section of the Nginx upgrade found that if you do not make upgrade upgrade, recompile upgrade, you must stop, and then start to use the new version! -->

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.