Nginx as static image server and proxy server.

1. create image_servers.conf in ..../nginx/conf

server{#you can access images by http://localhost:8000/images
    listen 8000;
    server_name localhost;

    location /images/{
        root /share/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }
}

server{#you can access images by http://localhost:9000/images
    listen 9000;
    server_name localhost;

    location /images/{
        root /share/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }
}

2. create upstream_image_servers.conf in ..../nginx/conf

upstream image_backend{#weight
    server 127.0.0.1:8000 weight=10 max_fails=1 fail_timeout=5;
    server 127.0.0.1:9000 weight=10;
    #server 127.0.0.1:10000 backup;
}

upstream image_backend1{#ip_hash
    ip_hash;
    server 127.0.0.1:8000;
    server 127.0.0.1:9000;
}

#upstream image_backend2{#select server according to server responding
#    server 127.0.0.1:8000;
#    server 127.0.0.1:9000;
#    fair;#third party
#}

#upstream image_backend3{#url hash
#    server 127.0.0.1:8000;
#    server 127.0.0.1:9000;
#    hash $request_uri;
#    hash_method crc32;
#}

3. create http_proxy_cache.conf in ..../nginx/conf

proxy_connect_timeout 10;
proxy_read_timeout 180;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_temp_path /tmp/temp_dir;
proxy_cache_path /tmp/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=3d max_size=10g;

4. include above created conf files in http block of ..../nginx/conf/nginx.conf

http {                      
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    include image_servers.conf;
    include http_proxy_cache.conf;
    include upstream_image_servers.conf;
}

 5. server the static files, and use proxy_cache.

    server {
        listen       80;
        server_name  10.197.60.137;

        location ~ .*\.(gif|jpg|png|css|js)(.*) {
            proxy_cache cache_one;
            proxy_cache_valid 200 302 24h;
            
            proxy_cache_valid 301 304 30d;
            proxy_cache_valid any 5m;
            expires 90d;
            add_header X-Cache HIT-Linux;
            proxy_cache_key $host$uri$is_args$args;
            
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://image_backend;
            proxy_redirect off;
        }

 

 

转载于:https://www.cnblogs.com/jmbkeyes/archive/2013/01/15/2861262.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值