nginx开机启动

1.首先,在linux系统的/etc/init.d/目录下创建nginx文件

vim /etc/init.d/nginx

2.加入脚本

 #!/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: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/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

或者脚本:

 #!/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: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/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

源码来源于:https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/

注意其中

nginx=”/usr/sbin/nginx” 修改成nginx执行程序的路径。

NGINX_CONF_FILE=”/etc/nginx/nginx.conf” 修改成配置文件的路径。

3.设置文件权限

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

4.使用chkconfig进行管理

先将nginx服务加入chkconfig管理列表:

chkconfig --add /etc/init.d/nginx

加完这个之后,就可以使用service对nginx进行启动,重启等操作了。

service nginx start
service nginx stop

注意:如果是刚配置好chkconfig管理,要多敲几次service nginx stop 命令(刚加入有可能稍等下,命令才有效)

5.设置终端模式开机启动:

chkconfig nginx on

php开机启动

前提需要正确配置php-fpm

vim /etc/init.d/php-fpm

内容如下

#!/bin/sh
# chkconfig: # description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \ # with some additional features useful for sites of any size, especially busier sites.
# DateTime: -- # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm}) lockfile=/var/lock/subsys/phpfpm start() {
[ -x ${phpfpm} ] || exit
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
${phpfpm} -t
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null >&
} case "$1" in
start)
rh_status_q && exit
$
;;
stop)
rh_status_q || exit
$
;;
restart|configtest)
$
;;
reload)
rh_status_q || exit
$
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit
esac

再就是加到开机启动项里面去

chkconfig --add php-fpm

然后启动

service php-fpm start    // 启动
service php-fpm stop // 停止

故障一:权限被拒绝

env: /etc/init.d/php-fpm: Permission denied

解决办法:

把/etc/rc.d/init.d/php-fpm 权限改为0755   或者 chmod a+x /etc/init.d/php-fpm

故障二:php-fpm出现乱码(而且文件变的很大二十几兆)

解决办法:

1.备份当前php-fpm

2. 新建php-fpm

ssh  > vim /etc/rc.d/init.d/php-fpm

3.输入代码:

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0. version.
# chkconfig: -
# 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: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=
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
[ -x $nginxd ] || exit
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && 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
esac
exit $RETVAL

其他参考:

https://blog.csdn.net/u013870094/article/details/52463026

https://www.cnblogs.com/jimisun/p/8057156.html

linux nginx,php开机启动的更多相关文章

  1. 不同linux系统添加开机启动程序的命令

    see http://phpcj.org/blog/%E4%B8%8D%E5%90%8Clinux%E7%B3%BB%E7%BB%9F%E6%B7%BB%E5%8A%A0%E5%BC%80%E6%9C ...

  2. linux Nginx服务开机自启

    linux Nginx服务开机自启 Nginx 是一个很强大的高性能Web和反向代理服务器.虽然使用命令行可以对nginx进行各种操作,比如启动等,但是还是根据不太方便.下面介绍在linux下安装后, ...

  3. Linux系统入门---开机启动流程

    目录 Linux系统入门---开机启动流程 一.centos6 二.systemd管理进程 1.查看级别 三.centos7实践案例: 1.案例1:centos7系统,单用户修改root密码 案例2: ...

  4. linux系统设置服务开机启动3种方法,Linux开机启动程序详解

    linux系统设置服务开机启动 方法1:.利用ntsysv伪图形进行设置,利用root登陆 终端命令下输入ntsysv 回车:如下图     方法2:利用命令行chkconfig命令进行设置 简要说明 ...

  5. Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动

    Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动 >>>>>>>>>>>>>> ...

  6. Windows 安装nginx并开机启动

    Win安装nginx并 开机启动 下载nginx安装包 nginx-1.12.2.zip,解压到D盘. https://pan.baidu.com/s/1InQa527yq35Q68c73RBb-A# ...

  7. Linux上设置开机启动Java程序

    在Linux上设置开机启动Java程序,例如:test.jar 在Linux上启动Java程序的命令: nohup java -jar test.jar >/dev/>& & ...

  8. Linux系统的开机启动顺序

    Linux系统的开机启动顺序加载BIOS–>读取MBR–>Boot Loader–>加载内核–>用户层init一句inittab文件来设定系统运行的等级(一般3或者5,3是多用 ...

  9. linux下安装nginx后开机启动篇

    众所周知nginx安装后需要手动去启动,每次开机之后都要执行nginx的启动命令很蛋疼.那么我们来让nginx开机启动吧 1.先創建一個nginx文件把 [root@localhost ~]# vi ...

  10. arm linux中添加开机启动

    微处理器:S5PV210操作系统:linux3.0.8 前言:    在产品中,基本上都要屏蔽arm开发板中linux系统的对外通信,只应该通过产品的相关APP做相关操作.    因此需要把该APP添 ...

随机推荐

  1. keepalived+nginx双机热备+负载均衡

    Reference: http://blog.csdn.net/e421083458/article/details/30092795 keepalived+nginx双机热备+负载均衡 最近因业务扩 ...

  2. php类库安装xml

    问题 报错:Call to undefined function dom_import_simplexml() yum install php-dom service restart httpd 参考 ...

  3. 地铁盾构管片姿态测量软件(Excel)

    记得11年刚开始从事盾构测量的时候,只知道搬站(倒站),测导线,还有就是测量管片.觉得最麻烦的就是在每个管片上面放个水平长尺,用全站仪测出他的水平位置和高程,但当时是本子记录每个数据,回去在敲到电脑上 ...

  4. 未能加载文件或程序集”xxxx”或它的某一个依赖项,试图加载格式不正确的程序。

    通常是因为应用程序编译的目标平台与引用的DLL类库目标平台不一致造成的,如应用程序目标编译为64位,而引用了32位的DLL. 在Visual Studio修改应用程序目标编译平台即可. 更多关于目标编 ...

  5. 【微信小程序】数据与界面UI不同步,不能直接操作Page.data

    问题:数据层与UI不同步 微信小程序也采用UI绑定数据源的形式,根据以前做WPF的经验,直觉上认为修改了数据层(Page.data)后,UI会自动更新,然而实验发现数据层修改后UI层未修改,导致数据层 ...

  6. [iptables]iptables常规设置

    转自:http://leil.plmeizi.com/archives/centos-iptables%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95%E8%BD%AC/ 关闭 ...

  7. jQuery笔记三——text/html/val/attr/prop

    1.获得内容 三个简单实用的用于 DOM 操作的 jQuery 方法: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() ...

  8. 根据时间获取最新数据 SQL(每一个人或者每一项)

    -- 方法1 select a.* from table1 a from table1 b where b.name=a.name and b.gdtime>a.gdtime) -- 方法2 s ...

  9. 超级简单却不知道:html标签的嵌套规则

    XHTML的标签有许多:div.ul.li.dl.dt.dd.h1~h6.p.a.addressa.span. strong……我们在运用这些标签搭建页面结构的时候,是可以将它们无限嵌套的,但是,嵌套 ...

  10. Sword protobuf学习二

    编写protobuf消息文件 文件格式: xxx.proto //标明使用哪个版本的protobuf,默认2.0版本 syntax = "proto3"; //类似于c++中的na ...