您好,登錄后才能下訂單哦!
[root@nginx nginx-1.12.2]# cd /usr/local/nginx/logs/
[root@nginx logs]# ls
access.log error.log nginx.pid
[root@nginx logs]# date
2019年 11月 14日 星期四 13:49:11 CST
[root@nginx logs]# date -d "0 day" "+%Y%m%d"
20191114 //以字符串形式顯示
[root@nginx logs]# date -d "-1 day" "+%Y%m%d"
20191113 //統計的是前一天
[root@nginx logs]# cd /opt/
[root@nginx opt]# ls
nginx-1.12.2 rh
[root@nginx opt]# touch aaa.txt
[root@nginx opt]# find /opt -name ".txt" //按名字進行查找
/opt/aaa.txt
[root@nginx opt]# find /opt -name ".txt" | rm -rf //后面跟刪除命令可以刪除嗎?
[root@nginx opt]# ls
aaa.txt nginx-1.12.2 rh //此時無法刪除
[root@nginx opt]# find /opt -name "*.txt" | xargs rm -rf //使用傳遞命令
[root@nginx opt]# ls
nginx-1.12.2 rh
//以上內容為Shell腳本中的常用手法:前面一條命令的執行結果,作為后面一條命令的參數
//創建日志分割腳本
[root@nginx opt]# vim fenge.sh
#!/bin/bash
#Filename:fenge.sh
d=$(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_path
mv /usr/local/nginx/logs/access.log ${logs_path}/test.com-access.log-$d
kill -USR1 $(cat $pid_path)
find $logs_path -mtime +30 | xargs rm -rf
//按Esc退出插入模式,輸入:wq保存退出
[root@nginx opt]# chmod +x fenge.sh
[root@nginx opt]# ./fenge.sh
[root@nginx opt]# cd /var/log/
[root@nginx log]# ls
anaconda glusterfs rhsm vmware-vmusr.log
audit grubby_prune_debug sa wpa_supplicant.log
boot.log lastlog samba wtmp
btmp libvirt secure Xorg.0.log
chrony maillog speech-dispatcher Xorg.0.log.old
cron messages spooler Xorg.1.log
cups nginx sssd Xorg.9.log
dmesg ntpstats tallylog yum.log
dmesg.old pluto tuned
firewalld ppp vmware-vgauthsvc.log.0
gdm qemu-ga vmware-vmsvc.log
[root@nginx log]# cd nginx/
[root@nginx nginx]# ls
test.com-access.log-20191113
[root@nginx nginx]# date -s 2019-11-13
2019年 11月 13日 星期三 00:00:00 CST
[root@nginx nginx]# date
2019年 11月 13日 星期三 00:00:15 CST
[root@nginx nginx]# ls
test.com-access.log-20191113 test.com-access.log-20191115
[root@nginx nginx]# cd /opt/
[root@nginx opt]# ls
fenge.sh nginx-1.12.2 rh
[root@nginx opt]# ./fenge.sh
[root@nginx opt]# cd /var/log/nginx/
[root@nginx nginx]# ls
test.com-access.log-20191112 test.com-access.log-20191113
[root@nginx nginx]# cd /usr/local/nginx
[root@nginx nginx]# ls
client_body_temp fastcgi_temp logs sbin uwsgi_temp
conf html proxy_temp scgi_temp
[root@nginx nginx]# cd logs/
[root@nginx logs]# ls
access.log error.log nginx.pid
//日志文件在啟動時自動產生
[root@nginx logs]# umount /aaa
[root@nginx logs]# mount.cifs //192.168.10.193/rpm /aaa
Password for root@//192.168.10.193/rpm:
[root@nginx logs]# ls /aaa/rpm
ls: 無法訪問/aaa/rpm: 沒有那個文件或目錄
[root@nginx logs]# ls /aaa
apr-1.6.2.tar.gz error.png nginx-1.12.2.tar.gz
apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 php-7.1.10.tar.bz2
awstats-7.6.tar.gz lf.jpg php-7.1.20.tar.gz
cronolog-1.6.2-14.el7.x86_64.rpm mysql-5.6.26.tar.gz
Discuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz
[root@nginx html]# vim index.html
<h2>Welcome to nginx!</h2>
<img src="lf.jpg"/>
//在welcome下一行插入圖片行,格式如上,修改完后輸入:wq保存退出
[root@nginx html]# vim /usr/local/nginx/conf/nginx.conf
//76行做如下修改:
location ~\.(gif|jepg|jpg|ico|bmp|png)$ {
root html;
expires 1d;
}
}
//在default_type下行插入以下內容:
http {
include mime.types;
default_type application/octet-stream;
server_tokens on;
//在worker_connections下行插入以下內容:
events {
worker_connections 1024;
}
user nginx nginx;
//修改完成后按Esc退出插入模式,輸入:wq保存退出
[root@nginx html]# service nginx stop
[root@nginx html]# service nginx start
####方法一:隱藏版本號
[root@nginx ~]# curl -I http://192.168.18.136/
HTTP/1.1 200 OK
Server: nginx/1.12.2 //此處顯示Nginx版本號
Date: Tue, 12 Nov 2019 20:59:15 GMT
Content-Type: text/html
Content-Length: 632
Last-Modified: Tue, 12 Nov 2019 16:39:13 GMT
Connection: keep-alive
ETag: "5dcae031-278"
Accept-Ranges: bytes
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
//在default_type下一行插入以上內容,修改完成后按Esc后輸入:wq保存退出
[root@nginx ~]# service nginx stop
[root@nginx ~]# service nginx start
[root@nginx ~]# curl -I http://192.168.18.136/
HTTP/1.1 200 OK
Server: nginx //此時版本號被隱藏
Date: Tue, 12 Nov 2019 21:07:13 GMT
Content-Type: text/html
Content-Length: 632
Last-Modified: Tue, 12 Nov 2019 16:39:13 GMT
Connection: keep-alive
ETag: "5dcae031-278"
Accept-Ranges: bytes
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
server_tokens on; //把off改為on
//修改完成后按Esc退出插入模式,輸入:wq保存退出
[root@nginx conf]# cd /opt
[root@nginx opt]# ls
fenge.sh nginx-1.12.2 rh
[root@nginx opt]# cd nginx-1.12.2/
[root@nginx nginx-1.12.2]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
[root@nginx nginx-1.12.2]# cd src/
[root@nginx src]# ls
core event http mail misc os stream
[root@nginx src]# cd core/
[root@nginx core]# ls
nginx.c ngx_cycle.h ngx_output_chain.c ngx_rwlock.c
nginx.h ngx_file.c ngx_palloc.c ngx_rwlock.h
ngx_array.c ngx_file.h ngx_palloc.h ngx_sha1.c
ngx_array.h ngx_hash.c ngx_parse.c ngx_sha1.h
ngx_buf.c ngx_hash.h ngx_parse.h ngx_shmtx.c
ngx_buf.h ngx_inet.c ngx_parse_time.c ngx_shmtx.h
ngx_conf_file.c ngx_inet.h ngx_parse_time.h ngx_slab.c
ngx_conf_file.h ngx_list.c ngx_proxy_protocol.c ngx_slab.h
ngx_config.h ngx_list.h ngx_proxy_protocol.h ngx_spinlock.c
ngx_connection.c ngx_log.c ngx_queue.c ngx_string.c
ngx_connection.h ngx_log.h ngx_queue.h ngx_string.h
ngx_core.h ngx_md5.c ngx_radix_tree.c ngx_syslog.c
ngx_cpuinfo.c ngx_md5.h ngx_radix_tree.h ngx_syslog.h
ngx_crc32.c ngx_module.c ngx_rbtree.c ngx_thread_pool.c
ngx_crc32.h ngx_module.h ngx_rbtree.h ngx_thread_pool.h
ngx_crc.h ngx_murmurhash.c ngx_regex.c ngx_times.c
ngx_crypt.c ngx_murmurhash.h ngx_regex.h ngx_times.h
ngx_crypt.h ngx_open_file_cache.c ngx_resolver.c
ngx_cycle.c ngx_open_file_cache.h ngx_resolver.h
//修改nginx.h內核文件,但是后期需要重新編譯安裝
[root@nginx core]# vim nginx.h
#define NGINX_VERSION "1.1.5"
//修改完成后按Esc退出插入模式,輸入:wq保存退出
[root@nginx core]# cd ../../
[root@nginx nginx-1.12.2]# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES 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 OK
Server: nginx/1.1.5
Date: Tue, 12 Nov 2019 21:38:05 GMT
Content-Type: text/html
Content-Length: 632
Last-Modified: Tue, 12 Nov 2019 16:39:13 GMT
Connection: keep-alive
ETag: "5dcae031-278"
Accept-Ranges: bytes
//此時顯示的版本號就是我們修改過的1.1.5
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。