Nginx使用(配置开机启动)
环境:
系统:CentOS 6.5 Final
安装目录:/usr/local/nginx
Nginx开机自启:
①编写shell实现控制
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: /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
更改访问权限:
chmod a+x /etc/init.d/nginx
测试效果:
[root@localhost ~]# /etc/init.d/nginx stop
停止 nginx: [确定]
[root@localhost ~]# /etc/init.d/nginx start
正在启动 nginx: [确定]
[root@localhost ~]# /etc/init.d/nginx restart
停止 nginx: [确定]
正在启动 nginx: [确定]
[root@localhost ~]# /etc/init.d/nginx stop
停止 nginx: [确定]
[root@localhost ~]# /etc/init.d/nginx sto
Usage: nginx {start|stop|restart|reload|status|help}
[root@localhost ~]# /etc/init.d/nginx restart
停止 nginx: [失败]
正在启动 nginx: [确定]
②使用该shell配置开机启动
法一:
vi /etc/rc.local
添加一行
/etc/init.d/nginx start
保存并退出,重启生效。
法二:
chkconfig --add nginx //添加索引
chkconfig --level nginx on //开机启动
重启生效。
③添加自定义命令(使用nginx代替/etc/init.d/nginx,启动nginx再也不用输那么长命令了)
vi /root/.bashrc
追加
alias nginx="/etc/init.d/nginx"
重启生效。
参考:
Linux下的Nginx安装(开机自启动):http://www.cnblogs.com/meteoric_cry/archive/2011/01/27/1945882.html
Linux下chkconfig命令详解:http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html
nginx documentation:http://nginx.org/en/docs/
Nginx使用(配置开机启动)的更多相关文章
- nginx配置开机启动及配置sudo授权启动
1.https://www.cnblogs.com/whatmiss/p/7091220.html 配置开机启动nginx 2.sudo授权其它用户启动 (1)root用户编辑 visu ...
- Linux下配置Nginx(在root的/etc/rc.local里配置开机启动功能http://tengine.taobao.org/)
上面是下载的包下载地址 http://tengine.taobao.org/download_cn.html nginx官网http://nginx.org/ 下一步 下一步 其中remote为重要属 ...
- yum 安装nginx(配置开机启动)
yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx 已加载插件:fastest ...
- linux nginx,php开机启动
nginx开机启动 1.首先,在linux系统的/etc/init.d/目录下创建nginx文件 vim /etc/init.d/nginx 2.加入脚本 #!/bin/bash # nginx St ...
- centos LAMP第二部分apache配置 下载discuz!配置第一个虚拟主机 安装Discuz! 用户认证 配置域名跳转 配置apache的访问日志 配置静态文件缓存 配置防盗链 访问控制 apache rewrite 配置开机启动apache tcpdump 第二十节课
centos LAMP第二部分apache配置 下载discuz!配置第一个虚拟主机 安装Discuz! 用户认证 配置域名跳转 配置apache的访问日志 配置静态文件缓存 配置防盗链 ...
- Linux开机启动顺序启动顺序及配置开机启动
Linux:开机启动顺序启动顺序及配置开机启动 开机启动顺序 1.加载内核 2.启动 init(/etc/inittab) pid=1 3.系统初始化 /etc/rc.d/rc.sysinit 4.运 ...
- OS X下安装Redis及配置开机启动
1.下载redis源码包redis-3.0.5.tar(此步骤可在图形界面下操作) 2.解压源码包 tar zxvf redis-3.0.5.tar 3.编译源码并安装 #进入源码目录 cd redi ...
- Centos 配置开机启动脚本启动 docker 容器
Centos 配置开机启动脚本启动 docker 容器 Intro 我们的 Centos 服务器上部署了好多个 docker 容器,因故重启的时候就会导致还得手动去手动重启这些 docker 容器,为 ...
- 【RabbitMQ】 RabbitMQ配置开机启动
环境 系统:Linux(CentOS 7.2) Erlang环境:21.1(安装参考[Erlang]源码安装) RabbitMQ:3.7.9(安装参考[RabbitMQ] RabbitMQ安装) 配置 ...
随机推荐
- ApplicationContextAware的使用
一.这个接口有什么用? 当一个类实现了这个接口(ApplicationContextAware)之后,这个类就可以方便获得ApplicationContext中的所有bean.换句话说,就是这个类可以 ...
- 如何指定vim 的查找是从上往下还是从下往上[z]
vim 搜索可以是 / 或者 ?,前者是往下找,后者是往前找. 用 n 查找下一个的时候,就和这两个指令指定的方向相同.如果你想改变方向的话,比如想往下找,那么 / 完了直接回车就行了.表示再次使用上 ...
- 制作根文件系统之内核如何启动init进程
start_kernel其实也是内核的一个进程,它占用了进程号0,start_kernel的内容简写如下: asmlinkage void __init start_kernel(void) //内核 ...
- 23.Mysql应用优化
23.应用优化23.1 使用连接池应用启动时创建好连接,以供用户使用,而不是每次创建. 23.2 减少对Mysql的访问 23.2.1 避免对同一数据做重复检索合并简单查询,减少访问次数. 23.2. ...
- Mac下安装社区版MongoDB
MongoDB下载地址:https://www.mongodb.com/download-center?_ga=2.98072543.1777419256.1515472368-391344272.1 ...
- (转帖)CentOS最常用命令及快捷键整理
原文:http://www.centoscn.com/CentOS/help/2014/0306/2493.html 最近开始学Linux,在VMware Player中安装了CentOS 6.4.为 ...
- MS-Office使用技巧
1.角标设置 下角标:选中(Shift+左右方向键)-->Ctrl+= 上角标:选中(Shift+左右方向键)-->Ctrl+Shift+=(Ctrl++) 撤销:同样操作 2.MS Of ...
- libnet 库使用(一)
该库的相关资料主要从源码包中获得(假设当前路径为源码包路径): ./sample 中有代码示例 ./doc/html 中html文件可以通过浏览器打开,参看函数定义 想要的基本上sample中都 ...
- oralce的lag和lead函数
https://www.cnblogs.com/always-online/p/5010185.html
- jmeter脚本录制的两种方式
完成一次完整的性能测试: 1.创建用户: 2.选择协议(HTTP) 3.使用工具去模拟协议操作(1.手工编写(抓包工具):2.工具自带录制) 4.运行工具进行压力测试