安裝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)。
相關文章
相關標籤/搜索