安装nginx做图片服务器

 

安装nginx
Wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz
或者此地址:http://lnamp-web-server.googlecode.com/files/pcre-8.13.tar.gz
tar zxvf pcre-8.13.tar.gz

./configure 
make 
make install

由于centos没有默认的nginx软件包,需要启用REHL的附件包
rpm -Uvh http://download.Fedora.RedHat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
或者此地址:http://mirrors.ustc.edu.cn/fedora/epel//5/i386/epel-release-5-4.noarch.rpm
yum -y install nginx

添加开机启动nginx 
vim /etc/rc.local
添加/usr/sbin/nginx

启动 /usr/sbin/nginx 
重启 /usr/sbin/nginx -s reload 
停止 /usr/sbin/nginx -s stop 
测试配置/usr/sbin/nginx -t

修改nginx配置文件/etc/nginx/nginx.conf




Java代码 
1.worker_processes 4; 
2.error_log /var/log/nginx/error.log crit; 
3.worker_connections 51200; 
4.keepalive_timeout 120; 
5.gzip on; 
6.gzip_min_length 1k; gzip_buffers 4 16k;#注意此处,不是416 gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css text/html application/xml text/javascript; 
7. gzip_vary on; 
8.
9.server { 
10. listen 80; 
11. server_name *.frady.cn *.frady.com.cn; 
12. set $htdocs /web/www/ROOT/;#此处定义了htdocs 
13. root $htdocs; 
14.
15. location ~ ^/zanStatus/ { 
16. stub_status on; 
17. access_log off; 
18. } 
19. location / { 
20. index index.html; 
21. } 
22. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ { 
23. expires 30d; 
24. } 
25.#此目录的图片不缓存 
26.location ^~ /picture/price/{ 
27.expires -2; 
28.} 
29. location ~*.(jsp|do|action|php|asp|rar|zip|txt|html|htm|shtml)$ 
30. { 
31. deny all; 
32. } 
33. location ~^/(WEB-INF)/{ 
34. deny all; 
35. } 
36.} 
worker_processes  4;
error_log  /var/log/nginx/error.log crit; 
worker_connections  51200;
keepalive_timeout  120;
gzip  on;
gzip_min_length   1k;   gzip_buffers     4 16k;#注意此处,不是416   gzip_http_version 1.0;   gzip_comp_level 2;   gzip_types  text/plain application/x-javascript text/css text/html application/xml text/javascript;  
   gzip_vary on; 

server {
        listen 80;
        server_name *.frady.cn *.frady.com.cn;
        set $htdocs /web/www/ROOT/;#此处定义了htdocs
        root $htdocs;
        
	location ~ ^/zanStatus/ {
            stub_status on;
            access_log off;
         }
	location / {
                index index.html;
        }
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ {
                expires 30d;
        }
#此目录的图片不缓存
location ^~ /picture/price/{
expires -2;
}
        location ~*.(jsp|do|action|php|asp|rar|zip|txt|html|htm|shtml)$
        {
           deny all;
	}
        location ~^/(WEB-INF)/{
           deny all;
        }
}

 完成
status参数解释
Active connections:145 
#nginx 正处理的活动连接数145个。
server accepts handled requests
 1749 1749 3198 
#nginx启动到现在共处理了 1749个连接 ,nginx启动到现在共成功创建 1749次握手 请求丢失数=(握手-连接),可以看出,我们没丢请求;总共处理了3198 次请求。
Reading: 0 Writing: 3 Waiting: 142 
#Reading :nginx读取到客户端的Header信息数。
#Writing : nginx返回给客户端的Header信息数。
#Waiting : Nginx已经处理完正在等候下一次请求指令的驻留连接.开启keep-alive的情况下,这个值等于active–(reading+writing)。  

你可能感兴趣的:(安装nginx做图片服务器)