nginx的web缓存的设置
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
先安装/hcdata/software/pcre-8.37
./configure
make && make install
./configure --user=www \
> --group=www \
> --prefix=/hcdata/server/nginx \
> --with-http_stub_status_module \
> --with-http_ssl_module \
> --with-http_gzip_static_module \
> --with-openssl=/usr/local/src/openssl-1.0.1c \
> --with-pcre=/hcdata/software/pcre-8.37 \
> --with-pcre-jit \
> --add-module=/hcdata/software/ngx_cache_purge-2.3
make && make install
接着nginx.conf的配置图片的缓存
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wmv|txt)$
{
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
proxy_pass http://ip:8098;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
server {
listen 8098;
server_name ip;
location / {
root /hcdata/www;
autoindex on;
}
proxy_pass 必须和proxy_cache成对出现 不然实现不了缓存
添加purge:
location ~ /purge(/.*) {
allow all;
proxy_cache_purge cache_one $host$1$is_args$args;
}
其中出现404错误 原因是此location没有放在
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wmv|txt)$ {
。。。。
}之前
正确的顺序是:
server {
listen 80;
server_name uadmin;
charset utf-8;
#access_log logs/host.access.log main;
location ~ /purge(/.*) {
allow all;
proxy_cache_purge cache_one $host$1$is_args$args;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wmv|txt)$
{
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
# root /hcdata/www;
# autoindex on;
proxy_pass http://*.*.*.*:8098;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location / {
# proxy_cache cache_one;
# proxy_cache_valid 200 304 12h;
# proxy_cache_valid 301 302 1m;
# proxy_cache_valid any 1m;
# proxy_cache_key $host$uri$is_args$args;
proxy_pass http://uadmin;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Connection Close;
proxy_set_header X-Forwarded-For $remote_addr;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache‘s document root
# concurs with nginx‘s one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
server {
listen 8098;
server_name *.*.*.*;
location / {
root /hcdata/www;
autoindex on;
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。