网站首页 > 技术教程 正文
方式一:传统方法
一、启动
cd usr/local/nginx/sbin
./nginx
二、重启
更改配置重启nginx
kill -HUP 主进程号或进程号文件路径
或者使用
cd /usr/local/nginx/sbin
./nginx -s reload
判断配置文件是否正确
nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd /usr/local/nginx/sbin
./nginx -t
三、关闭
查询nginx主进程号
ps -ef | grep nginx
从容停止 kill -QUIT 主进程号
快速停止 kill -TERM 主进程号
强制停止 kill -9 nginx
若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
kill -信号类型 '/usr/local/nginx/logs/nginx.pid'
方式二:通过配置/etc/init.d/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
:wq 保存并退出
设置文件的访问权限
chmod a+x /etc/init.d/nginx (a+x ==> all user can execute 所有用户可执行)
这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx…
同样的修改了nginx的配置文件nginx.conf,也可以使用上面的命令重新加载新的配置文件并运行,
配置开机自启动:
方式一:在/etc/rc.local中配置
可以将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了
vi /etc/rc.local
加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效。
方式二:将nginx配置成自启动的服务
1.添加至服务管理列表,并让其开机自动启动
[root@nginx ~]# chkconfig --add nginx
[root@nginx ~]# chkconfig nginx on
[root@nginx ~]# chkconfig nginx --list
nginx 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
2、nginx启动、停止、无间断服务重启
[root@example ~]# service nginx start
[root@example ~]# service nginx stop
[root@example ~]# service nginx reload
3.查看一下端口
[root@nginx ~]# netstat -ntlp | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3889/nginx
对于其他服务也同样适用,比如Mysql,php-fpm等等
10.测试一下
猜你喜欢
- 2024-10-09 kubernetes--pod资源的重启策略和健康检查
- 2024-10-09 Jenkins+Gitlab+Nginx发布与回退基于tag的项目(解决重复构建)
- 2024-10-09 HC免费开源物业系统Centos下重启后服务重新启动操作步骤
- 2024-10-09 Nginx之4包罗万象 - (虚拟主机)(nginx 虚拟ip)
- 2024-10-09 nginx-负载均衡具体实现策略及场景
- 2024-10-09 jenkins重启(Jenkins重启命令)
- 2024-10-09 nginx 改变您的HTTP服务器的缺省banner
- 2024-10-09 干货!通过Nginx实现中转的功能(nginx转换)
- 2024-10-09 docker容器自动重启配置(docker自动重启机制)
- 2024-10-09 如何在多容器 Docker Compose 应用程序中重启单个容器?
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)