user nginx;
worker_processes 8;
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by thisprocess.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
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;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plainapplication/x-javascript text/css application/xml;
gzip_vary on;
#注:proxy_temp_path和proxy_cache_path指定的路徑必須在同一分區
proxy_temp_path /data0/proxy_temp_dir;
#設置Web緩存區名稱為cache_one,內存緩存空間大小為200MB,1天沒有被訪問的內容自動清除,硬盤緩存空間大小為5GB。
proxy_cache_path /data0/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=5g;
server #此處為緩存服務器
{
listen 80;
server_name your_server_ip;
location /
{
proxy_cache cache_one;
#對不同的HTTP狀態碼設置不同的緩存時間
proxy_cache_valid 200 304 12h;
#以域名、URI、參數組合成Web緩存的Key值,Nginx根據Key值哈希,存儲緩存內容到二級緩存目錄內
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://your_server_ip:8080; #此處跳轉到真實的圖片服務器
log_format cache '***$time_local '
'$upstream_cache_status '
'Cache-Control: $upstream_http_cache_control '
'Expires: $upstream_http_expires '
'"$request" ($status) '
'"$http_user_agent" '; #定義日志格式(此日志格式可以顯示hit miss等,顯示緩存是否被擊中,老版本默認可以,但是新版本,發現需要加上這個)
access_log /var/log/nginx/cache.log cache; #使用這個日志格式
expires 1d;
}
#用於清除緩存,假設一個URL為http://192.168.8.42/test.txt,通過訪問http://192.168.8.42/purge/test.txt就可以清除該URL的緩存。
location ~ /purge(/.*)
{
#設置只允許指定的IP或IP段才可以清除URL緩存。
allow 127.0.0.1;
deny all;
#proxy_cache_purge cache_one$host$1$is_args$args;
}
#擴展名以.php、.jsp、.cgi結尾的動態應用程序不緩存。
location ~ .*\.(php|jsp|cgi)?$
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log off;
}
#真實的圖片服務器
server
{
listen 8080;
server_name your_server_ip;
location /
{
root /;
}
access_log /usr/local/webserver/nginx/logs/nginx_access.log;
}
}
把上面的your_server_ip 改為自己服務器IP.就搞定了..然后輸入 nginx -t 測試一下配置有沒有問題..沒問題就nginx -s reload.
然后你輸入your_server_ip:8080/images/pic_name 你就可以訪問到你的圖片了.如果403什么的話,可以試試 chmod 777 your_images_folder.
有問題可以留言交流哦..noob nginx conf...O(∩_∩)O
