Nginx as static image server and proxy server.
2013-01-15 15:21
489 查看
1. create image_servers.conf in ..../nginx/conf
2. create upstream_image_servers.conf in ..../nginx/conf
3. create http_proxy_cache.conf in ..../nginx/conf
4. include above created conf files in http block of ..../nginx/conf/nginx.conf
5. server the static files, and use proxy_cache.
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; }
相关文章推荐
- Using Nginx As Reverse-Proxy Server On High-Loaded Sites
- user rails3.2 host xml-rpc server as a blog proxy
- Using the Apache HTTP Server as a forward proxy to the Internet
- Setting up Django and your web server with uWSGI and nginx
- How.To.Process.Image.Infomation.Of.Rotate.And.Flip.From.Server
- static, const, reference and class object, as datamembers
- How to declare and initialize a static const array as a class member?
- Setting up Django and your web server with uWSGI and nginx
- Android:How to upload .mp3 file and image to http server?
- Setting up Django and your web server with uWSGI and nginx
- Codedom and Static Proxy - Codedom is my lover
- Nginx-proxy_buffer_size and fastcgi_buffer
- Firewalld Rich and Direct Rules: Setting up RHEL 7 Server as a Router
- OpenSSL and SslStream(C# as server)
- The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported.
- Install Nginx with PHP5 and MySQL (LEMP) in Ubuntu 13.10 Server
- Reverse Proxy Web Sockets with Nginx and Socket.IO
- How to config synergy between ubuntu as server and windows client
- Nginx and reverse proxy
- Perlbal is our Perl-based reverse proxy load balancer and web server