# Wgethttp: // response
# Wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz // Clear Cache module
# Tar zxvpf ngx_cache_purge-1.3.tar.gz-C ../software/
# CDs/usr/local/src/software/nginx-1.0.2
#./Configure -- user = nobody -- group = nobody -- prefix =/usr/local/nginx-1.0.2 -- with-http_stub_status_module -- with-http_ssl_module -- add-module = ../ngx_cache_purge-1.3
# Mkdir-p/www/nginx/proxy_temp_path
# Mkdir-p/www/nginx/proxy_cache_path
Nginx. conf configuration file:
User nobody;
Worker_processes 4;
Error_log logs/error. log crit;
Pid logs/nginx. pid;
Worker_rlimit_nofile 65535;
Events {
Use epoll;
Worker_connections 65535;
}
Http {
Server_tokens off;
Include mime. types;
Default_type application/octet-stream;
Server_names_hash_bucket_size 128;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
Keepalive_timeout 65;
Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
Upstream mysrv {
Server 192.168.1.1: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
Server 192.168.1.2: 80 weight = 1 max_fails = 2 fail_timeout = 30 s;
}
Include vhost/*. conf;
}
Aaa_example_com.conf configuration file:
Server {
Listen 80;
Server_name aaa.example.com;
Index. php index.html index.htm index.shtml;
Log_format proxy '$ remote_addr | $ upstream_addr | $ connection | $ upstream_status | $ time_local | $ request |'
'$ Status | $ body_bytes_sent | $ bytes_sent | $ http_referer |'
'$ Http_user_agent | $ upstream_response_time | $ msec | $ request_time ';
Access_log logs/aaa_access.log proxy;
Location/
{
Proxy_pass http: // mysrv;
Proxy_set_header Host $ host;
Proxy_set_header X-Forwarded-For $ remote_addr;
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf | js | css) $
{
Proxy_pass http: // mysrv;
Include proxy. conf;
}
Location ~ /Purge (/.*)
{
Allow 127.0.0.1;
Allow 192.168.1.0/24;
Deny all;
Proxy_cache_purge cache_one $ host $1 $ is_args $ args;
}
}
Proxy. conf configuration file:
Proxy_redirect off;
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Client_max_body_size 50 m; // maximum number of bytes allowed for client requests per file
Client_body_buffer_size 256 k; // maximum number of bytes requested by the buffer proxy to buffer the client
Proxy_connect_timeout 30; // timeout value for connecting to the backend server
Proxy_send_timeout 30; // timeout value for sending data to the backend server
Proxy_read_timeout 60; // The timeout time for the backend server to respond to the request
Proxy_buffer_size 4 k; // the cache size of the proxy request
Proxy_buffers 4 32 k;
Proxy_busy_buffers_size 64 k; // The proxy_buffers size that can be applied for when the system is busy
Proxy_temp_file_write_size 64 k; // proxy cache temporary file size
Proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; // failover
Proxy_max_temp_file_size 128 m;
Proxy_temp_path/www/nginx/proxy_temp_path;
Proxy_cache_path/www/nginx/proxy_cache_path levels = keys_zone = cache_one: 200 m inactive = 1d max_size = 1g; // Set the web cache zone name to cache_one, the memory cache space is 200 MB. the cache data that has not been accessed for more than one day is automatically cleared, and the hard disk cache space is 1 GB.
Proxy_cache cache_one; // use the web cache zone cache_one
Proxy_cache_valid 200 304 12 h;
Proxy_cache_valid 301 302 1 m;
Proxy_cache_valid any 1 m;
Proxy_cache_key $ host $ uri $ is_args $ args; // sets the key value of the web cache. nginx stores the cache based on the md5 hash of the key value.
The proxy_set_header command is used to add the specified Header information when initiating a request to the backend web server of the reverse proxy. when the backend web server has multiple domain name-based virtual hosts, you must add the Header Host to specify the domain name of the request so that the backend web server can identify the virtual Host that handles the reverse proxy access request.