1.从nginx官网(http://nginx.org/) 下载,我在此选择1.12.0版本。
2.安装之前需要安装依赖包,我这里直接用yum安装。
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum -y install openssl openssl-devel
3.装完依赖包后进入nginx目录用./configure --help查看安装选项,我在这里用
./configure --with-http_stub_status_module --prefix=/usr/local/nginx --with-debug --with-http_sub_module 出现这样代表nginx安装成功,然后执行make,make install。 执行 #whereis nginx 出现内容代表成功。 4.设置启动服务 在/etc/init.d下编辑nginx文件,往里面添加
#!/bin/sh
# chkconfig: 2345 85 15
# Startup script for the nginx Web Server
# description: nginx is a World Wide Web server.
# It is used to serve HTML files and CGI.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx deamon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
d_start(){
$DAEMON || echo -n "already running"
}
d_stop(){
$DAEMON -s quit || echo -n "not running"
}
d_reload(){
$DAEMON -s reload || echo -n "can not reload"
}
case "$1" in
start)
echo -n "Starting DESC:DESC:NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping DESC:DESC:NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC conf..."
d_reload
echo "reload ."
;;
restart)
echo -n "Restarting DESC:DESC:NAME"
d_stop
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
保存退出 设置文件的访问权限 # chmod +x /etc/init.d/nginx 添加nginx到启动服务里 # chkconfig --add nginx 设置nginx开机启动 # chkconfig nginx on 查看nginx是否开机启动 chkconfig --list nginx 5.添加nginx全局变量 ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx 编辑 /etc/profile文件,在文档最后添加 PATH=$PATH:/usr/local/nginx/sbin export PATH :wq!保存退出, 执行 source /etc/profile 6.运行nginx service nginx start,打开网站出现 运行成功
