nginx信号说明相关说明

信号名称 作用
TERM,INT 快速关闭
QUIT 从容关闭
HUP 重新加载配置,用新的配置开始新的工作进程,从容关闭旧的工作进程
USR1 重新打开日志文件
USR2 平滑升级可执行程序
WINCH 从容关闭工作进程

hup信号优雅重启

a.html

<html>
<h>这里是a.html文件</h>
<script>
window.location.href='./';
</script>
</html>

index.html

<html>
<h>这里是index.html文件</h>
<script>
window.location.href='./';
</script>
</html>

查看当前nginx的配置文件

server{
listen 80;
server_name localhost;
root /Users/lidong/www;
index index.html index.htm;
access_log /Users/lidong/wwwlogs/access.log;
error_log /Users/lidong/wwwlogs/error.log;
}

修改nginx的配置文件,将nginx设置为默认读取a.html

server{
listen 80;
server_name localhost;
root /Users/lidong/www;
index a.html index.html index.htm;
access_log /Users/lidong/wwwlogs/access.log;
error_log /Users/lidong/wwwlogs/error.log;
}
ps aux|grep nginx
lidong 5019 0.0 0.0 4339176 1136 ?? S 11:16上午 0:00.01 nginx: worker process
lidong 352 0.0 0.0 4339176 1480 ?? S 五08上午 0:00.05 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
lidong 5284 0.0 0.0 4277252 824 s000 S+ 2:04下午 0:00.01 grep nginx

通过ps命令得到nginx的master进程id为352,通过hup信号重启配置

kill -HUP 352

打开浏览器不断观察发现使用信号HUP后会自动的跳转到a.html,我们并没有重启,而且发现不是立马的跳转是过几秒后跳转的,这就是优雅的重新读取nginx的配置文件,从容的关闭旧的进程。

USR1重读日志


server{
listen 80;
server_name localhost;
root /Users/lidong/www;
index index.html index.htm;
access_log /Users/lidong/wwwlogs/access.log;
error_log /Users/lidong/wwwlogs/error.log;
}
刷新http://localhost/index.html 页面

查看日志情况
QiongdeMacBook-Pro:wwwlogs lidong$ ls -l
total 80
-rw-r--r-- 1 lidong staff 16201 3 30 14:36 access.log
QiongdeMacBook-Pro:wwwlogs lidong$ mv access.log access.log.bak
QiongdeMacBook-Pro:wwwlogs lidong$ ls -l
total 88
-rw-r--r-- 1 lidong staff 16410 3 30 14:42 access.log.bak

从上面可以看出来虽然改变了log日志文件的名称,但是log日志还是在写入,出现这问题的原因linux中文件识别是以文件node的id来的。

使用USR1信号用再次刷新
QiongdeMacBook-Pro:wwwlogs lidong$ kill -USR1 352
QiongdeMacBook-Pro:wwwlogs lidong$ ls -l
total 88
-rw-r--r-- 1 lidong staff 0 3 30 14:49 access.log
-rw-r--r-- 1 lidong staff 16410 3 30 14:42 access.log.bak
-rw-r--r-- 1 lidong staff 252 3 30 14:28 error.log
QiongdeMacBook-Pro:wwwlogs lidong$ ls -l
total 96
-rw-r--r-- 1 lidong staff 418 3 30 14:49 access.log
-rw-r--r-- 1 lidong staff 16410 3 30 14:42 access.log.bak
-rw-r--r-- 1 lidong staff 252 3 30 14:28 error.log

通过USR1型号量来重读日志,继续刷新页面,会重新生成access.log日志文件,这个对于运维做日志的备份十分有作用。

这里有个小技巧,通过ps获取pid可以重新加载配置文件,平滑重启服务,但是感觉比较麻烦,我们可以使用如下方法操作.

查看配置文件知道nginx的pid存储在那个文件

kill -HUP `cat /usr/local/etc/nginx/nginx.pid`

USR2平滑升级

假设我们重新编译了新的版本的nginx,这个时候/usr/local/nginx/bin nginx 的版本就不是之前的版本了如果启动更新会报错。

kill -USR2 `cat /usr/local/etc/nginx/nginx.pid`

这个时候使用这个命令来平滑升级nginx服务器

点击进入本人github仓库查看更多

nginx信号量的更多相关文章

  1. 【Nginx系列】Nginx编译与安装

    Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器.Nginx是由Igor Sysoev为俄罗斯访问第二的Rambler.ru站点开发的. 一.Nginx ...

  2. 02-nginx信号量

    刚才完了nginx的编译,nginx的编译还是挺简单的.控制nginx:重启.关闭.只有孤零零的一个二进制文件nginx 通过信号来控制它,Linux操作系统进程与进程之间通过信号来通信.荷兰的一位计 ...

  3. Nginx日志按日切分及清理超期的日志文件

    Nginx的日志配置如下: #定义日志打印的格式 log_format main '$remote_addr - $remote_user [$time_local] "$request&q ...

  4. nginx反向代理+负载均衡+url重写+ssl认证

      Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄 ...

  5. Nginx 从入门到放弃(一)

    Nginx nginx的使用场景 静态资源服务 通过本地文件系统提供服务 反向代理服务 nginx的强大性能 缓存 负载均衡 API服务 OpenResty nginx优点 高并发.高性能 可扩展性好 ...

  6. Nginx日志按天切割基本配置说明

    1.声明日志格式 声明log    log位置                log格式; access_log logs/access.log main; 2.定义日志格式(以下为常用的日志格式 可 ...

  7. nginx日志文件切分

    定义cut_nginx_log.sh 日志文件脚本如下 #!/bin/bash#LOGS_PATH为日志存放路径LOGS_PATH=/weblog/nginx/logsYESTERDAY=$(date ...

  8. nginx入门(安装,启动,关闭,信号量控制)

    公司使用到了nginx,于是周末初步接触了一下nginx,立即被其简洁,优雅,高效的特性给迷住了.nginx是在是个好东西,配置极其简单,容易理解,极其高效,稍微一调优,ab测试10k并发,很轻松.比 ...

  9. nginx的信号量

    一.官方文档 https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/ 二.nginx进程说明 一般在nginx ...

随机推荐

  1. spring boot学习(十三)SpringBoot缓存(EhCache 2.x 篇)

    SpringBoot 缓存(EhCache 2.x 篇) SpringBoot 缓存 在 Spring Boot中,通过@EnableCaching注解自动化配置合适的缓存管理器(CacheManag ...

  2. 遍历HashMap的方法(四)

    Map map = new HashMap(); for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { Map.Entr ...

  3. memory prefix twi,tri,trans ,tetra out 4

    1● twi 二   2● tri 三   3● trans 超过,超载   4● tetra 立体  

  4. poj3461

    题解: 简单kmp 然而strlen时间号费啊 代码: #include<cstdio> #include<cstring> using namespace std; ; #d ...

  5. 使用Mockito时遇到的一些问题

    最近在使用Mockito时遇到了几个比较tricking的问题,在这里记录一下. 1.如果方法的参数或者返回类型是泛型通配符相关的(如<?>,<? extends XXX>), ...

  6. html头标签meta实现refresh重定向

    <html> <head> <meta http-equiv="content-type" content="text/html; char ...

  7. Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException

    最近在使用poi操作excel时发现一个问题,详细如下: Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethod ...

  8. 利用Teensy进行em410x卡模拟以及暴力破解em410x类门禁系统

    什么是低频?什么是EM410x? 首先,我不得不再次提一下那些工作在125khz频率下的低频卡(如:EM410X之类的),以便大家更好的阅读以下的内容. 什么是低频?以下就是低频的解释: 低频(LF, ...

  9. mysql-connector-java-3.1.10-bin-g.jar 和 mysql-connector-java-3.1.10-bin.jar两个文件有什么不同呀?

    MySQL Connector/J的文档里说: MySQL Connector/J is distributed as a .zip or .tar.gz archive containing the ...

  10. SWIFT中计算两个日期间隔多少小时

    SWIFT中如何计算两个日期间隔多少个小时,其实几句代码就可以搞定了,Very Easy,在Playground内输入以下代码 var date1 = "2015-06-26 8:15:10 ...