编译安装nginx-1.4.5.tar.gz

1. 创建用户www

# groupadd www

# useradd -g www www -s /sbin/nologin

# cat /etc/passwd | grep www

www:x:500:500::/home/www:/sbin/nologin


2. 安装所需依赖包

# yum install -y gcc.x86_64 gcc-c++.x86_64 ncurses-devel.x86_64 make bison.x86_64 bison-devel.x86_64 openssl-devel.x86_64 pcre-devel.x86_64

# tar xvf cmake-2.8.12.2.tar.gz        #安装高版本的cmake是为安装ndbcluster做准备

# ./bootstrap; make; make install    #cmake 的安装命令


3. 解压安装

# tar xvf nginx-1.4.5.tar.gz

# ./configure --prefix=/usr/local/nginx \

--user=apache \

--group=apache \

--with-http_ssl_module \

--with-http_stub_status_module \

--with-http_gzip_static_module


# make && make install


4. 修改配置文件

# vim /usr/local/nginx/conf/nginx.conf        #先改动一部分使能够启动

user www www;        #第一句话


5. 启动

# /etc/init.d/nginx start


若没没有修改配置文件直接启动,会出现下面的提示

nginx: [emerg] getpwnam("apache") failed


###启动脚本nginx

#!/bin/bash

# nginx           This shell script takes care of starting and stopping

#                 nginx (WWW server).

#chkconfig - 13 99

#2014-3-11vflong3rd release edtion

#Usage:

#chmod a+x nginx./nginx {start|stop|restart|status|test}

### BEGIN INIT INFO

# Provides: $nginx

# Required-Start:

# Required-Stop:

# Default-Start:

# Default-Stop: 0 1 2 3 4 5 6

# Short-Description: start|stop|status|restart|test nginx server

# Description: control nginx

### END INIT INFO


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/local/nginx/sbin

export PATH


CONF=/usr/local/nginx/conf/nginx.conf

PID=/usr/local/nginx/logs/nginx.pid

ACMD=$1


function fstatus() {

if [ -e "$PID" ]; then

echo "The nginx is running"

else

echo "The nginx is not running"

fi

}


function fstart() {

if [ -e "$PID" ]; then

echo "The nginx is running"

else

nginx -c $CONF && echo "nginx start OK"

fi

}


function fstop() {

if [ ! -e "$PID" ]; then

echo "The nginx is not running"

else

cat $PID | xargs kill -TERM && echo "nginx stop OK"

fi

}


function frestart() {

fstop && fstart

}


function ftest() {

nginx -t -c $CONF

}


function ferror() {

echo "Usage: nginx {start|stop|restart|status|test}"

}


case $ACMD in

"start")

fstart

;;

"stop")

fstop

;;

"restart")

frestart

;;

"status")

fstatus

;;

"test")

ftest

;;

*)

ferror

;;

esac















你可能感兴趣的:(nginx,centos)