经验不在于年限,在于积累---专注互联网软件开发

把工作当事业做,把项目当作品做!

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  55 Posts :: 0 Stories :: 66 Comments :: 0 Trackbacks
 

    最近Nginx比较火,听说性能和稳定性都比目前市场占有率第一的Apache Web服务器高一个档次。以前就想好好研究下Apache的,由于种种原因一直没有去做。这次既然有更强大的替代品出现,决定好好研究研究。首先,来看看Nginx的简介:

       Nginx("engine x") 是一个高性能的 HTTP 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的Rambler.ru 站点开发的,它已经在该站点运行超过四年多了。自Nginx 发布四年来,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。目前国内各大门户网站已经部署了Nginx,如新浪、网易、腾讯等;国内几个重要的视频分享网站也部署了Nginx,如六房间、酷6、迅雷看看等。

Nginx now hosts nearly 6% (13M) of all domains worldwide.

最近在开发迅雷客服系统(http://help.xunlei.com/),搭建测试环境的时候突然想到Nginx,不妨当成一次学习和练手的机会。

       目前Nginx的官网最新的稳定版本是nginx-0.7.65Linux下的源代码文件包是:nginx-0.7.65.tar.gz

一般编译nginx时,都要先安装pcrezlib等外部支持程序,然后编译安装nginx时指定这些外部支持程序的位置,这样nginx在每次启动的时候,就会去动态加载这些东西了。

(1) 下载安装外部支持库

cd /tmp
wget ftp:
//ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.gz
tar zxvf pcre-8.01.tar.gz
cd pcre
-8.01/
.
/configure
make 
&& make install
cd ..
/
 

(2) 安装Nginx。将nginx-0.7.65.tar.gz解压后,进行简单的编译安装:

tar zxvf nginx-0.7.65.tar.gz
cd nginx
-0.7.65/
.
/configure --prefix=/usr/local/nginx0765
make 
&& make install
cd 
/usr/local/nginx0765
 

(3) 启动Nginx

/usr/local/nginx0765/sbin/nginx

 

Nginx的配置文件主要是:/usr/local/conf/nginx.conf

客服系统的测试环境配置是:

[root@game-13 conf]# vi nginx.conf

#user  nobody;
worker_processes  
4;

#error_log  logs
/error.log;
#error_log  logs
/error.log  notice;
#error_log  logs
/error.log  info;

#pid  logs
/nginx.pid;


events 
{
     use epoll;
    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"';

    #access_log  logs
/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  
0;
    keepalive_timeout  
65;

    #gzip  on;
    server 
{
        listen       
80;
        server_name  localhost;
        #charset koi8
-r;
        #access_log  logs
/host.access.log  main;
        location 
/ {
            root   html;
            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;
        }

    }


    server 
{
        listen       
80;
        server_name  help.xunlei.com;
        #charset koi8
-r;
        #access_log  logs
/host.access.log  main;
        location 
/ {
            root   
/usr/local/htdocs/help.xunlei.com;
            index  index.html index.htm;
        }

    }

}

 

保存修改配置后,重新启动Nginx服务器:

/usr/local/nginx0765/sbin/nginx –s stop

/usr/local/nginx0765/sbin/nginx

这样,配置Host,就可以访问测试环境:http://help.xunlei.com


(友情提示:本博文章欢迎转载,但请注明出处:hankchen,http://www.blogjava.net/hankchen
posted on 2010-05-12 20:09 hankchen 阅读(847) 评论(0)  编辑  收藏 所属分类: 服务器+Tomcat+Jetty

只有注册用户登录后才能发表评论。


网站导航: