Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx Optimization-hiding version number, Web caching, Log Segmentation (1)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

# # add a picture to the web page, modify the configuration file information [root@localhost html] # vim / usr/local/nginx/conf/nginx.conf # # modify the configuration file events {worker_connections 1024;} user nginx nginx # # modify Nginx user and group # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~\. (gif | jepg | jpg | ico | bmp | png) ${# # support image format root html; # # site expires 1D # # Cache for one day} [root@localhost html] # service nginx stop # # disable enabling service [root@localhost html] # service nginx start 4, view the cache with fiddler

Log slicing for Nginx increases as the Nginx uptime increases. In order to easily grasp the running status of Nginx, you need to always pay attention to the fact that the log file is too large. The log file is a disaster for monitoring.

Regular log file cutting Nginx itself does not have the function of log segmentation, but it can be automatically cut through the script of Nginx signal control function, and log cutting can be carried out periodically through the planned task of Linux. Write a log partition script file [root@localhost ~] # vim fenge.sh # # write a script file #! / bin/bash#Filename:fenge.shd=$ (date-d "- 1 day"+% Y%m%d") # # display the time one day ago logs_path= "/ var/log/nginx" # the save path of the split log pid_path= "/ usr/local/nginx/ Logs/nginx.pid "# # path of pid [- d $logs_path] | | mkdir-p $logs_path # # create a directory if there is no directory mv / usr/local/nginx/logs/access.log ${logs_path} / test.com-access.log-$d## generate the original log file to the new path kill-USR1 $(cat $pid_path) # # end regenerating the new pid file find $logs_path-mtime + 30 | xargs rm- Rf # # Delete the log file from 30 days ago [root@localhost ~] # chmod + x fenge.sh # # give execution permission [root@localhost ~] #. / fenge.sh # # execute script file 2 Check log partition [root@localhost ~] # cd / var/log/nginx/ # # switch to [root@localhost nginx] # lstest.com-access.log-20191112 [root@localhost nginx] # date-s 2019-11-14 # # modify date tomorrow on Thursday, November 14, 2019, 00:00:00 CST [root@localhost nginx] # cd ~ [root@localhost ~] #. / fenge.sh # # re-execute the script [root@localhost ~] # cd / var/log/nginx/ [root@localhost nginx] # ls # # View the log file test.com-access.log-20191112 test.com-access.log-201911133 of log partition Set up periodic scheduled task [root@localhost nginx] # crontab-e # # periodic scheduled task 0 1 * / opt/fenge.sh Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report