前言:
此时各位老铁们对“linuxnginx非daemon”大约比较关怀,兄弟们都需要知道一些“linuxnginx非daemon”的相关资讯。那么小编同时在网络上搜集了一些有关“linuxnginx非daemon””的相关内容,希望姐妹们能喜欢,小伙伴们一起来了解一下吧!1.安装pcre依赖以支持正则
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar xzvf pcre-8.35.tar.gz
[root@localhost src]# cd pcre-8.35
[root@localhost pcre-8.35]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.35]# make
[root@localhost pcre-8.35]# make install
2.安装OpenSSL
openssl软件包是用于提供网站加密证书服务的程序文件,安装这些文件时需要自定义下服务程序的安装目录,以便于稍后调用它们的时候更可控
[root@localhost pcre-8.35]# cd /usr/local/src
[root@localhost src]# tar xzvf openssl-1.0.1h.tar.gz
[root@localhost src]# cd openssl-1.0.1h
[root@localhost openssl-1.0.1h]# ./config --prefix=/usr/local/openssl
[root@localhost openssl-1.0.1h]# make
[root@localhost openssl-1.0.1h]# make install
openssl软件包安装后默认会在/usr/local/openssl/bin目录中提供很多的可用命令,咱们需要像刚刚那样把这个目录添加到PATH环境变量中,并写入到配置文件里,最后执行一下source命令以便让新的PATH环境变量内容可以立即生效:
[root@localhost pcre-8.35]# vim /etc/profile
………………省略部分输出信息………………
65 for i in /etc/profile.d/*.sh ; do
66 if [ -r "$i" ]; then
67 if [ "${-#*i}" != "$-" ]; then
68 . "$i"
69 else
70 . "$i" >/dev/null
71 fi
72 fi
73 done
74 export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin
75 unset i
76 unset -f pathmunge
[root@localhost pcre-8.35]# source /etc/profile (立即生效)
3.安装zlib
[root@localhost pcre-8.35]# cd /usr/local/src
[root@localhost src]# tar xzvf zlib-1.2.8.tar.gz
[root@localhost src]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@localhost zlib-1.2.8]# make
[root@localhost zlib-1.2.8]# make install
4.安装nginx开始
[root@localhost zlib-1.2.8]# cd ..
[root@localhost src]# useradd www -s /sbin/nologin
[root@localhost src]# tar xzvf nginx-1.6.0.tar.gz
[root@localhost src]# cd nginx-1.6.0/
[root@localhost nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35
[root@localhost nginx-1.6.0]# make
[root@localhost nginx-1.6.0]# make install
5.开机脚本文件
[root@localhost nginx-1.6.0]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /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
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@localhost nginx-1.6.0]# chmod 755 /etc/rc.d/init.d/nginx
[root@localhost nginx-1.6.0]# /etc/rc.d/init.d/nginx restart
Restarting nginx (via systemctl): [ OK ]
[root@localhost nginx-1.6.0]# chkconfig nginx on (开机启动)
完
欢迎吐槽
标签: #linuxnginx非daemon