Nginx的安装
这里介绍的是编译安装,开始安装之前需要安装gcc编译环境,ubuntu下可以使用
apt-get install build-essential
apt-get install libtool
一、从网上下载的源码我们放置在/urs/local/src中
二、解压后都放在/usr/local中进行安装
三、接下来需要分别安装
1、安装 zlib1g-dev和libpcre3-dev
apt-get install zlib1g-dev libpcre3-dev -y
2、安装pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar -xzf pcre-8.21.tar.gz
./configure
make
make install
3、安装openssl
wget http://www.openssl.org/source/openssl-0.0.1c.tar.gz
./config
make
make install
4、安装zlib
wget http://www.zlib.net/zlib-1.2.8.tar.gz
./configure
make
make install
5、下载nginx和编译安装
(1)执行下面编译设置
./configure --prefix=/usr/local/nginx-1.2.3 \
--conf-path=/usr/local/nginx-1.2.3/nginx.conf \
--with-openssl=/usr/local/openssl-1.0.1c \
--with-http_ssl_module \
--with-pcre=/usr/local/pcre-8.21 \
--with-http_stub_status_module
(说明:很多编译安装的说明都没有设置conf-path,但是我没有设置的话,在make install 阶段会出现
cp: `conf/koi-win' and `/usr/local/nginx/conf/koi-win' are the same file错误)
(2)make
(3)make install
启动:
sudo /usr/local/web/nginx.0.8.15/sbin/nginx -c /usr/local/web/nginx.0.8.15/conf/nginx.conf
#带测试配置文件启动方法
sudo /usr/local/web/nginx.0.8.15/sbin/nginx -t
#从容停止
sudo kill -QUIT `cat /usr/local/web/nginx.0.8.15/nginx.pid`
#快速停止
sudo kill -INT `cat /usr/local/web/nginx.0.8.15/nginx.pid`
#平滑重启
sudo kill -HUP `cat /usr/local/web/nginx.0.8.15/nginx.pid`
为了操作方便,可以自己写一个nginx命令脚本,放到/etc/init.d下,并赋予其执行权限即可,详见代码
启动:service nginx start
停止:service nginx stop
重启:service nginx reconfigure
查看状态:service nginx status
#!/bin/bash
# v.0.0.1
# create by jackbillow at 2007.10.15
# nginx - This shell script takes care of starting and stopping nginx.
#
# chkconfig: - 60 50
# description: nginx [engine x] is light http web/proxy server
# that answers incoming ftp service requests.
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
nginx_path="/usr/local/nginx"
nginx_pid="/usr/local/nginx/logs/nginx.pid"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginx_path/sbin/nginx ] || exit 0
RETVAL=0
prog="nginx"
start() {
# Start daemons.
if [ -e $nginx_pid -a ! -z $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
if [ -e $nginx_path/conf/nginx.conf ];then
echo -n $"Starting $prog: "
$nginx_path/sbin/nginx -c $nginx_path/conf/nginx.conf &
RETVAL=$?
[ $RETVAL -eq 0 ] && {
touch /var/lock/subsys/$prog
success $"$prog"
}
echo
else
RETVAL=1
fi
return $RETVAL
}
# Stop daemons.
stop() {
echo -n $"Stopping $prog: "
# killproc -d 10 $nginx_path/sbin/nginx
killall nginx
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $nginx_pid /var/lock/subsys/$prog
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reconfigure)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|reconfigure|status}"
exit 1
esac
exit $RETVAL
编译参数说明:
--prefix=path —
Nginx安装路径。如果没有指定,默认为 /usr/local/nginx。
--sbin-path=path —
Nginx可执行文件安装路径。只能安装时指定,如果没有指定,默认为<prefix>/sbin/nginx。
--conf-path=path —
在没有给定-c选项下默认的nginx.conf的路径。如果没有指定,默认为<prefix>/conf/nginx.conf。
--pid-path=path —
指定nginx.pid的文件名,安装后该名字可以在nginx.cong文件中修改。如果没有指定,默认为 <prefix>/logs/nginx.pid。
--error-log-path=path —
在nginx.conf中没有指定error_log指令的情况下,默认的错误日志的路径。如果没有指定,默认为 <prefix>/logs/error.log。
--user=name —
在nginx.conf中没有指定user指令的情况下,默认的nginx使用的用户。如果没有指定,默认为 nobody。
--group=name —
在nginx.conf中没有指定user指令的情况下,默认的nginx使用的组。如果没有指定,默认为 nobody。
--with-http_ssl_module —
开启HTTP SSL模块,使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL
--with-pcre=path —
指定PCRE库路径。(PCRE为正则表达式库)
--with-pcre-jit — builds the PCRE library with “just-in-time compilation” support.