#下载nginx并且解压缩
cd ~
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar -zxvf nginx-1.6.2.tar.gz -C /usr/local/src/
cd /usr/local/src
#yum update
#yum makecache
#yum groupinstall development tools
#yum pcre-devel zlib-devel openssl-devel
#创建用户和组
groupadd -r nginx
useradd -r -g nginx -s /sbin/nologin -M nginx
#创建web根目录和nginx日志文件并且授予权限
mkdir -p /data/wwwroot
mkdir -p /var/log/nginx
chmod +w /data/wwwroot/
chmod +w /var/log/nginx/
chown -R nginx:nginx /data/wwwroot/
chown -R nginx:nginx /var/log/nginx/
#配置nginx
cd /usr/local/src/nginx-1.6.2/
./configure --user=nginx --group=nginx \
> --prefix=/usr/local/nginx \
> --sbin-path=/usr/local/nginx/sbin/nginx \
> --conf-path=/usr/local/nginx/etc/conf/nginx.conf \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/subsys/nginx.lock \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/longinx/access.log \
> --with-http_stub_status_module \
> --with-http_ssl_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_realip_module \
> --with-file-aio
make
make install
#做一个软链接,方便使用nginx命令
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
#配置nginx启动脚本
http://wiki.nginx.org/RedHatNginxInitScript
#拷贝链接中的启动脚本修改如下参数
nginx 和 NGINX_CONF_FILE对应的路径
并且把修改好的脚本写到/etc/init.d/nginx中
chmod +x /etc/init.d/nginx
#加入到开机启动
chkconfig --add nginx
chkconfig nginx on
#使用nginx管理脚本启动nginx
/etc/init.d/nginx start