一、將nginx包上傳至linux服務器/usr/local/yh目錄下
二、解壓
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# tar -zxvf nginx-nginx-1.11.10.tar.gz
三、設置配置信息
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# ./configure --prefix=/usr/local/yh/nginx
四、報錯./configure: error: the HTTP rewrite module requires the PCRE library.
解決方式:安裝pcre-devel
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# yum -y install pcre-devel
五、重複步驟3,報錯./configure: error: the HTTP gzip module requires the zlib library.
解決方式:安裝zlib-devel
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# yum -y install zlib-devel
六、編譯
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# make
七、安裝
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# make install
八、檢查安裝是否成功
[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
九、若有需求可修改配置文件/usr/local/yh/nginx/conf/nginx.conf
十、將網頁文件上傳至/usr/local/yh/nginx/html文件夾中
十一、啓動
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# ./nginx/sbin/nginx
查看進程
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# ps -ef|grep nginx
十二、在/etc/init.d/目錄下建立nginx文件
[root@iZbp1a8ff3mfuvmvb01ig5Z yh]# vi /etc/init.d/nginx
=====================================================================================================
#!/bin/bashhtml
# nginx Startup script for the Nginx HTTP Serverlinux
# it is v.0.0.2 version.nginx
# chkconfig: - 85 15web
# description: Nginx is a high-performance web and proxy server.bash
# It has a lot of features, but it's not for everyone.服務器
# processname: nginxui
# pidfile: /usr/local/yh/nginx/logs/nginx.pidrest
# config: /usr/local/yh/nginx/conf/nginx.conform
nginxd=/usr/local/yh/nginx/sbin/nginxserver
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 =====================================================================================================1三、修改nginx文件權限 [root@iZbp1a8ff3mfuvmvb01ig5Z init.d]# chmod a+x nginx1四、將ngix加入到rc.local文件中,這樣開機的時候nginx就默認啓動了 [root@iZbp1a8ff3mfuvmvb01ig5Z init.d]# vi /etc/rc.local /etc/init.d/nginx start