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 practice (log segmentation, picture cache, hidden version number)

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Example of Nginx log segmentation: [root@nginx nginx-1.12.2] # cd / usr/local/nginx/logs/ [root@nginx logs] # lsaccess.log error.log nginx.pid [root@nginx logs] # Thursday, November 14, date2019 13:49:11 CST [root@nginx logs] # date-d "0 day"+% Y%m%d" 20191114 / / display [root@nginx logs] # date-d "as a string" -1 day "+% Y%m%d" 20191113 / / Statistics from the previous day [root@nginx logs] # cd / opt/ [root@nginx opt] # lsnginx-1.12.2 rh [root@nginx opt] # touch aaa.txt [root@nginx opt] # find / opt-name ".txt" / / search by name / opt/aaa.txt [root@nginx opt] # find / opt-name ".txt" | rm-rf / / can I delete the delete command after it? [root@nginx opt] # lsaaa.txt nginx-1.12.2 rh// cannot delete [root@nginx opt] # find / opt-name "* .txt" at this time | xargs rm-rf / / use the passing command [root@nginx opt] # lsnginx-1.12.2 rh// as a common method in Shell scripts: the execution result of the previous command As an argument to the latter command, create the log segmentation script [root@nginx opt] # vim fenge.shengebinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinbinpool bashparts Filenameze fenge.shdpartition $(date-d "- 1 day"+% Y%m%d") logs_path= "/ var/log/nginx" pid_path= "/ usr/local/nginx/logs/nginx.pid" [- d $logs_path] | | mkdir-p $logs_pathmv / log $ {logs_path} / test.com-access.log-$dkill-USR1 $(cat $pid_path) find $logs_path-mtime + 30 | xargs rm-rf// press Esc to exit insert mode Input: wq save exit [root@nginx opt] # chmod + x fenge.sh [root@nginx opt] #. / fenge.sh [root@nginx opt] # cd / var/log/ [root@nginx log] # lsanaconda glusterfs rhsm vmware-vmusr.logaudit grubby_prune_debug sa wpa_supplicant.logboot.log lastlog samba wtmpbtmp Libvirt secure Xorg.0.logchrony maillog speech-dispatcher Xorg.0.log.oldcron messages spooler Xorg.1.logcups nginx sssd Xorg.9.logdmesg ntpstats tallylog yum.logdmesg.old pluto Tunedfirewalld ppp vmware-vgauthsvc.log.0gdm qemu-ga vmware-vmsvc.log [root@nginx log] # cd nginx/ [root@nginx nginx] # lstest.com-access.log-20191113 [root@nginx nginx] # date-s 2019-11-132019 Wednesday 13 November 1911 00:00:00 CST [root@nginx nginx] # Wednesday 13 November date2019 00:00:15 CST [root@ Nginx nginx] # lstest.com-access.log-20191113 test.com-access.log-20191115 [root@nginx nginx] # cd / opt/ [root@nginx opt] # lsfenge.sh nginx-1.12.2 rh [root@nginx opt] #. / fenge.sh [root@nginx opt] # cd / var/log/nginx/ [root@nginx nginx] # lstest.com-access.log-20191112 test.com-access.log-20191113 [root@nginx nginx] # cd / usr/local/nginx [root @ nginx nginx] # lsclient_body_temp fastcgi_temp logs sbin uwsgi_tempconf html proxy_temp scgi_ temp [root @ nginx nginx] # cd logs/ [root@nginx logs] # lsaccess.log error.log nginx.pid// log file automatically generates Nginx cache time instance at startup: [root@nginx logs] # umount / aaa [root@nginx logs] # mount.cifs / / 192.168.10.193/rpm / aaaPassword for root@//192.168.10.193/rpm: [root@nginx logs] # ls / aaa/rpmls: unable to access / aaa/rpm: there is no file or directory [root@nginx logs] # ls / aaaapr-1.6.2.tar.gz error.png nginx-1.12.2.tar.gzapr-util-1.6.0.tar.gz httpd -2.4.29.tar.bz2 php-7.1.10.tar.bz2awstats-7.6.tar.gz lf.jpg php-7.1.20.tar.gzcronolog-1.6.2-14.el7.x86_64.rpm mysql-5.6.26.tar.gzDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz [root @ nginx html] # vim index.html Welcome to nginx!

/ / insert a picture line on the next line of welcome with the format as above. After modification, enter: wq save, exit, and then refresh the web page before it will appear the picture we linked to:

[root@nginx html] # vim / usr/local/nginx/conf/nginx.conf//76 line is modified as follows: location ~\. (gif | jepg | jpg | ico | bmp | png) ${root html; expires 1d;}} / insert the following content in the default_type downlink: http {include mime.types; default_type application/octet-stream; server_tokens on / / insert the following in the lower line of worker_connections: events {worker_connections 1024;} user nginx nginx / / Press Esc to exit the insert mode after modification, and enter: wq save exit [root@nginx html] # service nginx stop [root@nginx html] # service nginx start at this time, oh, we refresh the web page and query the packet information of the image. We can see that the cache information of the image is: from November 12, 2019 to November 13, 2019, the cache time is one day.

Example of hidden version of Nginx:

# method 1: hide the version number

[root@nginx ~] # curl-I http://192.168.18.136/HTTP/1.1 200OKServer: nginx/1.12.2 / / the Nginx version number is shown here Date: Tue, 12 Nov 2019 20:59:15 GMTContent-Type: text/htmlContent-Length: 632Last-Modified: Tue 12 Nov 2019 16:39:13 GMTConnection: keep-aliveETag: "5dcae031-278" Accept-Ranges: bytes [root@nginx ~] # vim / usr/local/nginx/conf/nginx.confhttp {include mime.types Default_type application/octet-stream; server_tokens off / / insert the above content on the next line of default_type Press Esc after modification and enter: wq save exit [root@nginx ~] # service nginx stop [root@nginx ~] # service nginx start [root@nginx ~] # curl-I http://192.168.18.136/HTTP/1.1 200 OKServer: nginx / / at this time the version number is hidden Date: Tue, 12 Nov 2019 21:07:13 GMTContent-Type: text/htmlContent-Length: 632Last-Modified: Tue 12 Nov 2019 16:39:13 GMTConnection: keep-aliveETag: "5dcae031-278" Accept-Ranges: bytes method 2: forge the version number [root@nginx ~] # vim / usr/local/nginx/conf/nginx.confserver_tokens on / / change off to on// and press Esc to exit the insert mode after modification Input: wq save exit [root@nginx conf] # cd / opt [root@nginx opt] # lsfenge.sh nginx-1.12.2 rh [root@nginx opt] # cd nginx-1.12.2/ [root@nginx nginx-1.12.2] # lsauto CHANGES.ru configure html Makefile objs srcCHANGES conf contrib LICENSE man README [root@nginx nginx-1.12.2] # cd src/ [root@nginx src] # lscore event http mail misc os Stream [root@nginx src] # cd core/ [root@nginx core] # lsnginx.c ngx_cycle.h ngx_output_chain.c ngx_rwlock.cnginx.h ngx_file.c ngx_palloc.c ngx_rwlock.hngx_array.c ngx_file.h ngx_palloc.h ngx_sha1.cngx_array.h Ngx_hash.c ngx_parse.c ngx_sha1.hngx_buf.c ngx_hash.h ngx_parse.h ngx_shmtx.cngx_buf.h ngx_inet.c ngx_parse_time.c ngx_shmtx.hngx_conf_file.c ngx_inet.h ngx_parse_time.h Ngx_slab.cngx_conf_file.h ngx_list.c ngx_proxy_protocol.c ngx_slab.hngx_config.h ngx_list.h ngx_proxy_protocol.h ngx_spinlock.cngx_connection.c ngx_log.c ngx_queue.c ngx_string.cngx_connection.h ngx_log.h ngx_queue.h ngx _ string.hngx_core.h ngx_md5.c ngx_radix_tree.c ngx_syslog.cngx_cpuinfo.c ngx_md5.h ngx_radix_tree.h ngx_syslog.hngx_crc32.c ngx_module.c ngx_rbtree.c ngx_thread_pool.cngx_crc32.h ngx_module.h ngx_rbtree .h ngx_thread_pool.hngx_crc.h ngx_murmurhash.c ngx_regex.c ngx_times.cngx_crypt.c ngx_murmurhash.h ngx_regex.h ngx_times.hngx_crypt.h ngx_open_file_cache.c ngx_resolver.cngx_cycle.c ngx_open_file_cache.h ngx_resolver.h// modifies nginx.h kernel file But later, you need to recompile and install [root@nginx core] # vim nginx.h#define NGINX_VERSION "1.1.5" / / press Esc to exit the insert mode after the modification is completed. Enter: wq save exit [root@nginx core] # cd. /.. / [root@nginx nginx-1.12.2] # lsauto CHANGES.ru configure html Makefile objs srcCHANGES conf contrib LICENSE man README [root@nginx nginx-1.12.2] #. / configure\-- prefix=/usr/local/nginx\-- user=nginx\-- group=nginx\-- with-http_stub_status_ module [root @ nginx nginx-1.12.2] # make & & make install [root@nginx nginx-1.12.2] # service nginx stop [root@nginx nginx-1.12.2] # service nginx start [root@nginx nginx-1.12.2] # curl-I http://192.168.18.136/HTTP/1.1 200 OKServer: nginx/1.1.5Date: Tue 12 Nov 2019 21:38:05 GMTContent-Type: text/htmlContent-Length: 632Last-Modified: Tue, 12 Nov 2019 16:39:13 GMTConnection: keep-aliveETag: "5dcae031-278" Accept-Ranges: bytes// the version number displayed at this time is our modified version 1.1.5

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