1、将nginx包上传至linux服务器/usr/local/yh目录下
2、解压
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# tar -zxvf nginx-nginx-1.11.10.tar.gz
3、设置配置信息
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# ./configure --prefix=/usr/local/yh/nginx
4、报错./configure: error: the HTTP rewrite module requires the PCRE library.
解决方式:安装pcre-devel
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# yum -y install pcre-devel
5、重复步骤3,报错./configure: error: the HTTP gzip module requires the zlib library.
解决方式:安装zlib-devel
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# yum -y install zlib-devel
6、编译
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# make
7、安装
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# make install
8、检查安装是否成功
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# /usr/local/yh/nginx/sbin/nginx -t
显示以及信息即安装成功:
nginx: the configuration file /usr/local/yh/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/yh/nginx/conf/nginx.conf test is successful
9、如有需求可修改配置文件/usr/local/yh/nginx/conf/nginx.conf
10、将网页文件上传至/usr/local/yh/nginx/html文件夹中
11、启动
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# ./nginx/sbin/nginx
查看进程
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# ps -ef|grep nginx
12、在/etc/init.d/目录下创建nginx文件
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# vi /etc/init.d/nginx
=====================================================================================================
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/yh/nginx/logs/nginx.pid
# config: /usr/local/yh/nginx/conf/nginx.conf
nginxd=/usr/local/yh/nginx/sbin/nginx
nginx_config=/usr/local/yh/nginx/conf/nginx.conf
nginx_pid=/usr/local/yh/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# 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 $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
=====================================================================================================
13、修改nginx文件权限
[root@iZbp1a8ff3mfuvmvb01ig5Z init.d]# chmod a+x nginx
14、将ngix加入到rc.local文件中,这样开机的时候nginx就默认启动了
[root@iZbp1a8ff3mfuvmvb01ig5Z init.d]# vi /etc/rc.local
/etc/init.d/nginx start