Nginx配置图片服务器
[作者:遥方 时间:2010-4-24]
周未上天涯贴图专区抓了几万张图片^^_^^。现在来用NGINX展示一下。整理如下:
环境windowsXP + nginx配置图片服务器
其中我的图片存放目录在:E:/JaveProj/Process/WebRoot/tyimages
目录结构为:
Tyimages/
1/
2/
3/
…..
我的nginx配置文件内容如下:
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use select; #默认即为select
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format download '$remote_addr - $remote_user [$time_local]'
'"$request" $status $bytes_sent'
'"$http_referer" "$http_user_agent"'
'"$http_range" "$sent_http_content_range"';
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
#set client_header
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#开户GZIP压缩输出功能
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css application/xml image/jpeg; #表示对这些文件做GZIP压缩输出
output_buffers 1 32k;
postpone_output 1460;
#设置虚拟主机 可以配置多个虚拟主机 通过include的方式进行配置
server {
listen 8001;
server_name 127.0.0.1;
charset utf-8;
#设置虚拟主机的访问日志
access_log logs/ main;
#如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid
#如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好
location ~ ^/(img|js|css)/ {
root E:/temp;
expires 24h;
}
#定义图片服务器的目录位置。凡以jpg之类结尾的全部甩到此目录下面去
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
root E:/JaveProj/Process/WebRoot/tyimages;
expires 24h; #设置过期时间
}
location /(WEB-INF)/ {
deny all;
}
#设置网站的根目录
location / {
root E:/JaveProj/Process/WebRoot/tyimages;
index index.html index.htm;
}
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;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
|
以上配置完毕 之后开启NGINX。
访问即可
以上配置包含了GZIP压缩与图片过期机制。
我做过测试直接使用resin来读图片即这样
打开速度是非常慢的。也不知道是什么原因。而我现在将图片单独用nginx来跑的话发现速度是非常快的。
可能nginx真的是处理静态资源方面性能非常优秀吧。
现在可以非常快速地欣赏贴图专区的美图了哈哈^_^
阅读(2730) | 评论(0) | 转发(0) |