首页 > 系统相关 >将nginx交给service管理

将nginx交给service管理

时间:2024-02-05 11:05:59浏览次数:30  
标签:service reload stop echo nginx && 交给 chkconfig

#!/bin/bash
# chkconfig: 2345 99 99
prot=80
nginx=/usr/local/nginx/sbin/nginx
check(){
! $nginx -tq && echo "致命错误:配置文件错误" && exit
}
start(){
check
netstat -tln |grep -q ":80\>" && echo "$prot端口被占用" && exit
$nginx
}
stop_reload(){
check
! netstat -tlnp |grep -q "nginx" && echo "nginx 未运行"
$nginx -s $1 &> /dev/null
}
case "$1" in
start)
        start ;;
stop)
        stop_reload $1 ;;
restart)
        stop_reload stop &> /dev/null
        start ;;
reload)
        stop_reload $1 ;;
*)
        echo "用法:$(basename $0) <start|stop|restart|reload>" ;;
esac

将此脚本放至/etc/init.d/下即可用service启停

将nginx添加到chkconfig管理的开机启动中

  chkconfig --add nginx

  chkconfig nginx on



标签:service,reload,stop,echo,nginx,&&,交给,chkconfig
From: https://blog.51cto.com/u_16558404/9601571

相关文章

  • LVS Nginx HAProxy区别
    LVS抗负载能力强,性能高,能达到F5硬件的60%,对内存和cpu资源消耗比较低工作在四层仅作分发之用,通过vrrp协议转发,具体流量由linux内核处理,没有流量的产生稳定性、可靠性好,自身有完整的双机热备方案,如LVS+keepalived应用范围比较广,可以对所有应用做负载均衡配置性比较低,减少人为出错的概......
  • Nginx--安装&&配置文件
    官网:http://nginx.org/en/download.htmlnginx版本:1.18一 安装1下载预编译环境(预编译报错需要安装什么库直接在库名后面接-devel 使用yum下载)yum-yinstallpcre-developenssl-develgccgcc-c++2 创建用户,解压包useradd-M-r-s/sbin/nologinnginxtarxvfnginx-1.......
  • Nginx--安装模块
    一 安装系统自带模块#进入安装目录[root@localhost~]#cdnginx-1.18.0/#查看原来的编译选项[[email protected]]#nginx-V#查看安装的模块[[email protected]]#./configure--help#以http_v2_module为例[[email protected]]#./confi......
  • Nginx--调优
    1 Nginx运行工作进程数量(worker_processes)Nginx运行工作进程个数一般设置CPU的核心数或者auto,最多8个,8个以上性能提升不会再提升了,而且稳定性变得更低 2 Nginx运行CPU亲和力(worker_cpu_affinity)(全局快添加)nginx默认是没有开启利用多核cpu的配置的,需要通过增加worker_......
  • Nginx--用户认证&&访问控制&&限速&&状态访问
    一 用户认证某些网页只希望给特定的用户访问,可以设置用户认证,使用户访问时需要进行身份认证,只有认证通过才可访问网页location/{roothtml;indexindex.htmlindex.htm;auth_basic"haha";#服务器描述......
  • Nginx--虚拟主机
    一 基于域名server{listen80;server_namewww.google.com;location/{roothtml/google;indexindex.htmlindex.htm;}}server{listen80default;#default在浏览器中直接输入IP地址会进入这个......
  • Nginx--缓存
    一般存的是静态资源,可以提高客户端的访问速度,并减轻服务器的压力 1 客户端缓存通过设置expires指令,响应头中将会返回Expires和Cache-Control字段当浏览器发现响应头存在这样的缓存字段,当再次请求相同资源时,就会确认在客户端的资源是否过期location/{expires30m......
  • Nginx--rewrite
    rewriteURL重写,可以在改变网站结构后,无需要求客户端用户修改原有的浏览器书签,也无需其他网站修改对我们网站的友情链接,依赖于PCRE库的支持 1if语法:if(condition){...}默认值:—上下文:server,location如果condition为真,执行定义在大括号中的rewr......
  • Nginx--引用多配置文件
    在nginx.conf的http模块,include指定某个目录下的*.confusernginx;worker_processesauto;error_log/var/log/nginx/error.log;pid/run/nginx.pid;#Loaddynamicmodules.See/usr/share/nginx/README.dynamic.include/usr/share/nginx/modules/*.conf;events{......
  • Nginx--平滑升级
    在不中断服务的情况下,新的请求也不会丢失,使用新的nginx可执行程序替换旧的 1 查看老版本的编译选项[root@localhost~]#nginx-Vnginxversion:nginx/1.16.0builtbygcc4.8.520150623(RedHat4.8.5-44)(GCC)builtwithOpenSSL1.0.2k-fips26Jan2017TLSSNI......