【澳门金莎娱乐网站】把nginx加入到系统服务,

日期:2019-11-13编辑作者:服务器

三、Java运行环境之 cent os6.8 64位安装nginx,os6.8nginx

文章转载:

根据工作需要,现在需要安装nginx服务器,本来可以直接安装别人制作好的rpm包的,但是本着爱折腾和时刻尝鲜的精神,我决定从官网下载最新的nginx源码来安装,下面记录了我的安装过程。

下面的安装假定是以root用户登录并执行
1.安装依赖库
这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 
yum -y install make gcc gcc-c++ glibc glibc-devel lsof   
yum -y install pcre pcre-devel  
yum -y install zlib zlib-devel  
yum -y install openssl openssl--devel 

2.下载源码包
cd /usr/local/src
wget -d ""
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module 
make -j 4
make install

3.验证性启动nginx
注意,在没有设置nginx为系统服务之前,这里仅是验证性的启动测试。使用下面的命令查看nginx可执行程序的路径
whereis nginx
一般默认在/usr/local/nginx目录下面
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx

4.添加nginx为系统服务
添加如下文件

vim /etc/init.d/nginx

[html] view plain copy

  1. #!/bin/sh  
  2. #  
  3. # nginx - this script starts and stops the nginx daemon  
  4. #  
  5. # chkconfig:   - 85 15  
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse   
  7. #               proxy and IMAP/POP3 proxy server  
  8. # processname: nginx  
  9. # config:      /etc/nginx/nginx.conf  
  10. # config:      /etc/sysconfig/nginx  
  11. # pidfile:     /var/run/nginx.pid  
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14. # Source networking configuration.  
  15. . /etc/sysconfig/network  
  16. # Check that networking is up.  
  17. [ "$NETWORKING" = "no" ] && exit 0  
  18. nginx="/usr/local/nginx/sbin/nginx"  
  19. prog=$(basename $nginx)  
  20. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"  
  21. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx  
  22. lockfile=/var/lock/subsys/nginx  
  23. start() {  
  24.     [ -x $nginx ] || exit 5  
  25.     [ -f $NGINX_CONF_FILE ] || exit 6  
  26.     echo -n $"Starting $prog: "  
  27.     daemon $nginx -c $NGINX_CONF_FILE  
  28.     retval=$?  
  29.     echo  
  30.     [ $retval -eq 0 ] && touch $lockfile  
  31.     return $retval  
  32. }  
  33. stop() {  
  34.     echo -n $"Stopping $prog: "  
  35.     killproc $prog -QUIT  
  36.     retval=$?  
  37.     echo  
  38.     [ $retval -eq 0 ] && rm -f $lockfile  
  39.     return $retval  
  40. killall -9 nginx  
  41. }  
  42. restart() {  
  43.     configtest || return $?  
  44.     stop  
  45.     sleep 1  
  46.     start  
  47. }  
  48. reload() {  
  49.     configtest || return $?  
  50.     echo -n $"Reloading $prog: "  
  51.     killproc $nginx -HUP  
  52. RETVAL=$?  
  53.     echo  
  54. }  
  55. force_reload() {  
  56.     restart  
  57. }  
  58. configtest() {  
  59. $nginx -t -c $NGINX_CONF_FILE  
  60. }  
  61. rh_status() {  
  62.     status $prog  
  63. }  
  64. rh_status_q() {  
  65.     rh_status >/dev/null 2>&1  
  66. }  
  67. case "$1" in  
  68.     start)  
  69.         rh_status_q && exit 0  
  70.     $1  
  71.         ;;  
  72.     stop)  
  73.         rh_status_q || exit 0  
  74.         $1  
  75.         ;;  
  76.     restart|configtest)  
  77.         $1  
  78.         ;;  
  79.     reload)  
  80.         rh_status_q || exit 7  
  81.         $1  
  82.         ;;  
  83.     force-reload)  
  84.         force_reload  
  85.         ;;  
  86.     status)  
  87.         rh_status  
  88.         ;;  
  89.     condrestart|try-restart)  
  90.         rh_status_q || exit 0  
  91.             ;;  
  92.     *)      
  93.       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"  
  94.         exit 2  
  95. esac  

chmod +x /etc/init.d/nginx
注册 nginx 服务
chkconfig --add nginx
chkconfig --list nginx
假如查看到nginx服务在各种级别下,都没有打开,可以再次使用下面的命令明确指出在不同级别下打开:
chkconfig --level 2345 nginx on
再次采用
chkconfig --list nginx
查看,是否在上述各级别下已经打开。这里之所以要如此强调,是希望在断电后nginx服务能自动重启。

4.修改配置文件nginx.conf

主要是根据业务逻辑来配置nginx.conf,这里忽略具体内容

配置完成后,重新测试并加载nginx.conf
service nginx configtest
service nginx reload
让nginx在新的配置下运行就可以了

5.安装中出现的问题和错误
因为nginx.conf中出现问题,显示错误如下:
nginx: [emerg] unknown directive "lua_shared_dict" in /usr/local/nginx/conf/nginx.conf:11

nginx: [emerg] unknown directive "rewrite_by_lua_file" in /usr/local/nginx/conf/nginx.conf:136

解决方法

这两个报错,是因为nginx.conf中添加了这两个指令,将对应配置及逻辑删除就可以了。

参考链接

我暂时将它们注释掉    


0


0

查看评论

cent os6.8 64位安装nginx,os6.8nginx 文章转载: 根据工作需要,现在需要安装nginx服...

retval=$?

1.依赖 gcc openssl-devel pcre-devel zlib-devel
    安装:yum install gcc openssl-devel pcre-devel zlib-devel -y

# Source networking configuration.
. /etc/sysconfig/network

#安装zlib-devel

4.配置Nginx为系统服务,以方便管理
  1、在/etc/rc.d/init.d/目录中建立文本文件nginx
  2、在文件中粘贴下面的内容:

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
2、加入chkconfig
[[email protected] ~]# cp nginx /etc/init.d/
[[email protected] ~]# chmod 755 /etc/init.d/nginx
[[email protected] ~]# chkconfig --add nginx

#输入以下内容

注意修改成自己的安装目录!!!
3、修改nginx文件的执行权限
    chmod +x nginx
4、添加该文件到系统服务中去
    chkconfig --add nginx
    查看是否添加成功
    chkconfig --list nginx

restart() {
configtest || return $?
stop
sleep 1
start
}

restart() {

  1. 安装Nginx
    ./configure

  2. make && make install

3、nginx启动、停止、无间断服务重启
[[email protected] ~]# service nginx start
[[email protected] ~]# service nginx stop
[[email protected] ~]# service nginx reload

;;

Nginx安装步骤:

lockfile=/var/lock/subsys/nginx

mkdir -p $value && chown -R $user $value

启动,停止,重新装载
service nginx start|stop

 独自等待

stop

默认安装目录:
/usr/local/nginx

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}

force-reload)

#!/bin/sh
#
# 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:      /etc/sysconfig/nginx
# pidfile:     /var/run/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' -`
   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

rh_status() {
status $prog
}

wget -r -np -nd http://nginx.org/download/nginx-1.13.0.tar.gz

1、编写脚本,名为nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HT...

force_reload() {

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

# echo "creating" $value

force_reload() {
restart
}

configtest || return $?

# Source function library.
. /etc/rc.d/init.d/functions

$1

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

killproc $prog -QUIT

start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

if [ `echo $opt | grep '.*-temp-path'` ]; then

rh_status_q() {
rh_status >/dev/null 2>&1
}

;;

reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}

if [ -z "`grep $user /etc/passwd`" ]; then

1、编写脚本,名为nginx
#!/bin/sh
#
# 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: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid

 

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

force_reload

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

restart|configtest)

#

;;

# make required directories

fi

}

start)

return $retval

}

condrestart|try-restart)

}

[ $retval -eq 0 ] && rm -f $lockfile

chkconfig nginx on

# nginx - this script starts and stops the nginx daemon

$1

status)

}

;;

#解压nginx

;;

# Source networking configuration.

chmod a+x /etc/init.d/nginx

rh_status

[ -x $nginx ] || exit 5

stop() {

for opt in $options; do

# description: NGINX is an HTTP(S) server, HTTP(S) reverse

# Check that networking is up.

user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`

# processname: nginx

configtest || return $?

 

*)

#安装nginx

value=`echo $opt | cut -d "=" -f 2`

echo -n $"Starting $prog: "

sleep 1

esac

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

reload)

rh_status() {

make

fi

options=`$nginx -V 2>&1 | grep 'configure arguments:'`

#nginx默认安装在/usr/local/nginx

[ $retval -eq 0 ] && touch $lockfile

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

echo

if [ -n "$user" ]; then

echo

$1

rh_status_q && exit 0

start

if [ ! -d "$value" ]; then

#!/bin/sh

yum install -y zlib-devel

rh_status_q || exit 0

 

yum install -y pcre-devel

#授权

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Reloading $prog: "

return $retval

stop)

prog=$(basename $nginx)

rh_status_q || exit 0

$nginx -t -c $NGINX_CONF_FILE

# chkconfig: - 85 15

make_dirs() {

;;

#安装pcre

configtest() {

rh_status_q() {

restart

}

# Source function library.

rh_status >/dev/null 2>&1

echo -n $"Stopping $prog: "

# config: /etc/nginx/nginx.conf

# pidfile: /var/run/nginx.pid

case "$1" in

retval=$?

[ "$NETWORKING" = "no" ] && exit 0

澳门金莎娱乐网站,}

#开机启动

tar zxvf nginx-1.13.0.tar.gz

# config: /etc/sysconfig/nginx

echo

daemon $nginx -c $NGINX_CONF_FILE

lockfile=/var/lock/subsys/nginx

}

./configure

make_dirs

;;

rh_status_q || exit 7

reload() {

}

#配置nginx,需进入nginx目录

useradd -M -s /bin/nologin $user

start() {

killproc $nginx -HUP RETVAL=$?

# proxy and IMAP/POP3 proxy server

. /etc/rc.d/init.d/functions

make install

. /etc/sysconfig/network

exit 2

#下载nginx

nginx="/usr/local/nginx/sbin/nginx"

status $prog

#

fi

fi

vi /etc/init.d/nginx

done

}

#创建文件

设置开机启动:

#此时需要配置nginx 的配置文件

$1

本文由澳门金莎娱乐网站发布于服务器,转载请注明出处:【澳门金莎娱乐网站】把nginx加入到系统服务,

关键词:

腾讯服务器部署Centos,java搭建阿里云服务器环境

java搭建阿里云服务器环境(java环境+mysql+tomcat)和部署 JavaWeb 项目到云服务器(十分详细),阿里javaweb 最近在做项目...

详细>>

Nextcloud搭建过程,Centos7的apache网站环境搭建wor

网盘不可信赖 那就自个儿搭建256TB的网盘呗 — Nextcloud搭建进度,256tbnextcloud 二零一四年网盘的日子倒霉过啊 一家家...

详细>>

修改yum源为国内源,CentOS配置本地yum源

CentOS配置本地yum源/Ali云yum源/163yuan源,并配置yum源的优先级,centos163yuan 1.概述       YUM(全名为 Yellow dog Updater,...

详细>>

特性介绍和使用指南澳门金莎娱乐网站:,使用

.NET CORE的windows兼容包 第叁个,.NET Core的Windows包容包是二个很好的增加补充本领。当.NET Core2.0支出实现并盛产后,它...

详细>>