实验环境:RHEL6.0
Server:Server3.example.com
IP:192.168.0.3
1.安装配置Nginx
所需源码包:
pcre:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
nginx: http://nginx.org/download/nginx-1.3.14.tar.gz
gperftools:(优化nginx)http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
openssl:http://www.openssl.org/source/
zlib http://sourceforge.net/projects/libpng/files/zlib/
# yum install gcc make gcc-c++ -y
解压zlib、pcre、openssl、gperftools源码包!
1.1安装所需组件——pcre(提供rewrite模块)
【系统默认自带有pcre,如若提前卸载,则无法编译安装】
【源码包安装完毕后请勿删除,因为安装nginx时需要使用】
# tar zxf pcre-8.32.tar.gz
# cd pcre-8.32
# ./configure \
> --prefix=/usr/local/pcre-8.32 \
> --libdir=/usr/local/lib/pcre \
> --includedir=/usr/local/include/pcre
# make && make install
# vim /etc/ld.so.conf
***********************************
添加:
/usr/local/lib/pcre
***********************************
# ldconfig #载入动态函数库
1.2安装google-perftools
google-perftools包含四个工具:TCMalloc、heap-checker、heap-profiler和cpu-profiler,TCMalloc是google-perftools的其中一个工具,用于优化内存分配的效率和速度,帮助在高并发的情况下很好的控制内存的使用。
# tar zxf gperftools-2.0.tar.gz
# cd gperftools-2.0
# ./configure
# make&&make install
# echo "/usr/local/lib" >>/etc/ld.so.conf
# ldconfig
1.3安装Nginx
# useradd -M -s /sbin/nologin www
# cd nginx-1.3.14
# ./configure \
> --user=www \
> --group=www \
> --prefix=/usr/local/nginx \
> --pid-path=/usr/local/nginx/logs/nginx.pid \
> --error-log-path=/usr/local/nginx/logs/error.log \
> --http-log-path=/usr/local/nginx/logs/access.log \
> --with-http_stub_status_module \ #取得一些nginx的运行状态
> --with-http_ssl_module \
> --http-client-body-temp-path=/tmp/nginx_client \#客户端请求临时文件
> --http-proxy-temp-path=/tmp/nginx_proxy \
> --http-fastcgi-temp-path=/tmp/nginx_fastcgi \
> --with-http_gzip_static_module \ #启用时需要zlib
> --with-google_perftools_module \ #该模块能优化nginx
> --with-ld-opt='-l tcmalloc_minimal' \ #该模块能优化nginx
> --with-ipv6 \
> --with-pcre=/root/source/pcre-8.32/ \ #指定pcre的源码位置
> --with-openssl= /root/source/openssl-1.0.1e \ #指定openssl源码位置
> --with-zlib=/root/source/zlib-1.2.5 \ #指定zlib的源码位置
> --with-http_flv_module \ #支持对FLV文件的拖动播放
> --with-http_realip_module \ #支持显示真实来源IP地址
> --with-mail \ #允许POP3/IMAP4/SMTP代理模块
> --with-mail_ssl_module \#允许POP3/IMAP/SMTP可以使用SSL/TLS
#make
#make install
1.4 配置Nginx
# vim /usr/local/nginx/conf/nginx.conf
********************************************************************
user www;
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
google_perftools_profiles /var/tmp/tcmalloc;
worker_rlimit_nofile 1024;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
upstream server3.example.com {
server 192.168.0.4:80
weight=1 max_fails=3 fail_timeout=60s;
server 192.168.0.5:80
weight=1 max_fails=3 fail_timeout=60s;
}
access_log off;
error_log /dev/null;
sendfile on;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2; #压缩等级
gzip_types text/plain application/x-Javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name Server3.example.com;
#access_log logs/host.access.log;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include vhost/*.conf;
}
