1.nginx安装配置(包含purge模块)
下载purge模块:
wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
tar -zxvf ngx_cache_purge-2.1.tar.gz
配置 nginx,在相关地方加上如下的配置就可以了:
/root/lnmp0.7/upgrade_nginx.sh>增加
<code>--add-module=../ngx_cache_purge-2.1</code>
执行./upgrade_nginx.sh
输入版本号:1.2.3
2.配置 Proxy Cache
(Purge参照http://labs.frickle.com/nginx_ngx_cache_purge/)
nginx.conf 的 http部分追加+
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/cache/temp;
proxy_cache_path /home/cache/path levels=1:2 keys_zone=cache_one:30m inactive=7d max_size=20g;
(不使用Purge时,追加proxy_cache_path /home/cache/path levels=1:2 keys_zone=cache_one:30m inactive=7d max_size=20g;)
相关host.conf内部的location / {追加+
proxy_pass http://xx.xx.xx.xx/;
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;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 3d;
expires 10d;
# proxy_cache cache_one;
# proxy_cache_valid 200 304 3d;
# proxy_cache_key $host$uri$is_args$args;
# expires 10d;
(注释掉的部分为不使用Purge时的内容)
location ~ /purge(/.*) {
allow 127.0.0.1;
deny all;
proxy_cache_purge cache_one $host$1$is_args$args;
}
示例+
user www www;
worker_processes 2;
error_log /var/log/nginx_error.log crit;
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
##cache##
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/temp_dir;
proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
##end##
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_disable "MSIE [1-6]\.";
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
upstream appserver {
server 192.168.1.251;
}
server {
listen 80 default;
server_name www.gangpao.com;
location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
proxy_pass http://appserver;
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache cache_one;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
location ~ .*\.(php)(.*){
proxy_pass http://appserver;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log /usr/local/nginx/logs/www.gangpao.com.log;
}
}