nginx日志切割

nginx的日志文件没有rotate功能。如果你不处理,日志文件将变得越来越大,还好我们可以写一个nginx日志切割脚本来自动切割日志文件。

第一步就是重命名日志文件,不用担心重命名后nginx找不到日志文件而丢失日志。在你未重新打开原名字的日志文件前,nginx还是会向你重命名的文件写日志,linux是靠文件描述符而不是文件名定位文件。

第二步向nginx主进程发送USR1信号。

nginx主进程接到信号后会从配置文件中读取日志文件名称,重新打开日志文件(以配置文件中的日志名称命名),并以工作进程的用户作为日志文件的所有者。

重新打开日志文件后,nginx主进程会关闭重名的日志文件并通知工作进程使用新打开的日志文件。

工作进程立刻打开新的日志文件并关闭重名名的日志文件。

然后你就可以处理旧的日志文件了。

nginx日志按日期自动切割脚本如下

#nginx日志切割脚本
#author: http://www.nginx.cn
#!/bin/bash
#设置日志文件存放目录
logs_path="/usr/local/nginx/logs/"
#设置pid文件
pid_path="/usr/local/nginx/nginx.pid"
#重命名日志文件
mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y%m%d").log
#向nginx主进程发信号重新打开日志
kill -USR1 `cat ${pid_path}`

保存以上脚本nginx_log.sh,或者点此下载

crontab 设置作业

0 0 * * * bash /usr/local/nginx/nginx_log.sh

这样就每天的0点0分把nginx日志重命名为日期格式,并重新生成今天的新日志文件。

90 thoughts on “nginx日志切割

  1. Pingback: poker99

  2. Pingback: fun88

  3. Pingback: havaianas

  4. Pingback: p658#optymalizacja grafik

  5. Pingback: enlightened marketing

  6. Pingback: aircraft decals

  7. Pingback: rubiks.glove.co.il

  8. Pingback: Darknet

  9. Pingback: +18

  10. Pingback: https://exe-elit.pl/

  11. Pingback: Eddie Frenay

  12. Pingback: ウォーターサーバー

  13. Pingback: satta king

  14. Pingback: 카지노사이트

  15. Pingback: cbd oil

  16. Pingback: google adwords agency

  17. Pingback: ต้องการ กู้ เงิน ด่วน

  18. Pingback: 놀이터추천

  19. Pingback: 카지노사이트

  20. Pingback: Replica

  21. Pingback: 조커온라인바카라

  22. Pingback: 온라인카지노

  23. Pingback: https://enterthenews.pl/forum/

  24. Pingback: 카지노사이트

  25. Pingback: Replica rolex 16013 datejust

  26. Pingback: pomoshh-psihologa-online

  27. Pingback: psyhelp_on_line

  28. Pingback: coronavirus

  29. Pingback: PSYCHOSOCIAL

  30. Pingback: rasstanovka hellinger

  31. Pingback: 바카라 쿠폰

  32. Pingback: Cherekasi film 2020

  33. Pingback: 918kiss test id

  34. Pingback: film doktor_liza

  35. Pingback: djoker film

  36. Pingback: viagra

  37. Pingback: generic viagra

  38. Pingback: viagra online

  39. Pingback: buy viagra online

  40. Pingback: gidonline-filmix.ru

  41. Pingback: ciprofloxacin otc

  42. Pingback: koronavirus-v-ukraine-doktor-komarovskiy

  43. Pingback: Institutional Repository

  44. Pingback: yourfishguide.com mahi mahi fish

  45. Pingback: viagra generic

  46. Pingback: Canadian Pharmacies Online

  47. Pingback: Canadian Pharmacy

  48. Pingback: 강남 오피

  49. Pingback: t.me/psyhell

  50. Pingback: Ïñèõîëîã îíëàéí

  51. Pingback: bitly.com

  52. Pingback: viagra 100mg

  53. Pingback: viagra over the counter

  54. Pingback: over the counter viagra

  55. Pingback: viagra coupon

  56. Pingback: viagra for sale

  57. Pingback: cialis

  58. Pingback: cialis coupon

  59. Pingback: canadian pharmacy cialis

  60. Pingback: cialis 5mg

  61. Pingback: rlowcostmd.com

  62. Pingback: bitly

  63. Pingback: movies-tekstmovies-tekst

  64. Pingback: Zemlyane 2005 smotret onlajn

  65. Pingback: pharmacy

  66. Pingback: generic cialis

  67. Pingback: canadian parmacy viagra 100mg

  68. Pingback: smotret onlajn v horoshem kachestve hd

  69. Pingback: gusmeasu.com

  70. Pingback: malenkie-zhenshhiny-2020

  71. Pingback: dom 2

  72. Pingback: zoom-viber-skype

  73. Pingback: Vratar Galaktiki Film, 2020

  74. Pingback: Vratar

  75. Pingback: Cherkassy

  76. Pingback: chernobyl-hbo-2019-1-sezon

  77. Pingback: moskva-psiholog

  78. Pingback: batmanapollo.ru

  79. Pingback: 323

  80. Pingback: 525

  81. Pingback: dom2-ru

  82. Pingback: Tenet Online

  83. Pingback: where to buy real viagra online

  84. Pingback: psy psy psy psy

  85. Pingback: best online pharmacy for viagra

  86. Pingback: krsmi.ru

  87. Pingback: CFOSPUK

  88. Pingback: MAMprEj

  89. Pingback: fgu0ygW

  90. Pingback: http://cialistodo.com/

Comments are closed.