备注:系统采用Centos 6.4最小化安装


nginx部署

1.安装编译环境


yum -y install gcc automake autoconf libtool make gcc-c++



2.安装pcre,zlib,openssl(pcre为了重写rewrite,zlib为了gzip,openssl为了https)


pcre


[root@nginx ~]# cd /home/WGY

[root@nginx WGY]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz

[root@nginx WGY]# tar zxvf pcre-8.30.tar.gz

[root@nginx WGY]# cd pcre-8.30

[root@nginx WGY]# ./configure

[root@nginx WGY]# make && make install


zlib


[root@nginx WGY]#wget http://zlib.net/zlib-1.2.8.tar.gz

[root@nginx WGY]#tar zxvf zlib-1.2.8.tar.gz

[root@nginx WGY]#cd zlib-1.2.8

[root@nginx WGY]#./configure

[root@nginx WGY]#make && make install


openssl


[root@nginx WGY]#wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz

[root@nginx WGY]#tar zxvf openssl-1.0.1e.tar.gz


nginx

[root@nginx WGY]#wget http://tengine.taobao.org/download/tengine-1.5.2.tar.gz

[root@nginx WGY]#tar zxvf tengine-1.5.2.tar.gz

[root@nginx WGY]#cd tengine-1.5.2

[root@nginx tengine-1.5.2]# ./configure --with-http_ssl_module \

--with-pcre=/home/WGY/pcre-8.30 \

--with-zlib=/home/WGY/zlib-1.2.8 \

--with-openssl=/home/WGY/openssl-1.0.1e \

--with-http_upstream_check_module

[root@nginx tengine-1.5.2]# make && make install



3.nginx配置负载均衡


[root@nginx ~]# cat /usr/local/nginx/conf/nginx.conf

user www www;    

worker_processes 2;    


pid logs/nginx.pid;    


events {    

   use epoll;    

   worker_connections 65535;

}  


http {    

   include mime.types;

   default_type application/octet-stream;


 #  log_format main '$remote_addr - $remote_user [$time_local] '  

 #  '"$request" $status $bytes_sent '  

 #  '"$http_referer" "$http_user_agent" '  

 #  '"$gzip_ratio"';    


 #  log_format download '$remote_addr - $remote_user [$time_local] '  

 #  '"$request" $status $bytes_sent '  

 #  '"$http_referer" "$http_user_agent" '  

 #  '"$http_range" "$sent_http_content_range"';    


   client_header_buffer_size 1k;    

   large_client_header_buffers 4 4k;    


   #gzip on;    

   #gzip_min_length 1100;    

   #gzip_buffers 4 8k;    

   #gzip_types text/plain;    

   #output_buffers 1 32k;    

   #postpone_output 1460;    


 #  access_log logs/access.log main;    

   client_header_timeout 3m;    

   client_body_timeout 3m;    

   send_timeout 3m;    

   sendfile on;    

   tcp_nopush on;    

   tcp_nodelay on;    

   keepalive_timeout 65;    



   upstream mysvr {

      #ip_hash;    

       server 192.168.0.214;  

   }    


   server {    

       listen 80;    


         location / {    

           proxy_pass http://mysvr;

       }    


   }  

}  


[root@nginx ~]#