Linux study notes 12 weeks three lessons (April 25)

Source: Internet
Author: User
Tags local time

12.10 Nginx Access Log

vim/usr/local/nginx/conf/nginx.conf//Search Log_format

$remote _addr//client p (public IP)

IP $http _x_forwarded_for//proxy Server

$time _local//server local time

$host//Access host name (domain name)

$request _uri//visited URL address

$status//Status code

$http _referer//referer

$http _user_agent//user_agent

vim/usr/local/nginx/conf/vhost/test.com.conf //Edit the configuration file and add the following line to the server

----------------------------------------------------------------------------

Access_log/tmp/test.com.log Combined_realip

----------------------------------------------------------------------------

The combined_realip here is the name of the log format defined in nginx.conf

/USR/LOCAL/NGINX/SBIN/NGINX-T//Check configuration for errors

/usr/local/nginx/sbin/nginx-s Reload//reload, can also restart service

Curl-x127.0.0.1:80 Test.com-i

Cat/tmp/test.com.log


12.11 Nginx Log Cutting

vim/usr/local/sbin/nginx_log_rotate.sh//write the following:

------------------------------------------------------------------------------------

#! /bin/bash

# #假设nginx的日志存放路径为/data/logs/

D= ' date-d '-1 day +%y%m%d '//similar to 20180427, yesterday's date, today 28th

Logdir= "/data/logs"

Nginx_pid= "/usr/local/nginx/logs/nginx.pid"

CD $logdir

For log in ' ls *.log '

Do

MV $log $log-$d

Done

/bin/kill-hup ' Cat $nginx _pid '

--------------------------------------------------------------------------------------

Add Task Schedule #crontab-e//write the following:

0 0 * * */bin/bash/usr/local/sbin/nginx_logrotate.sh//Daily 0 o'clock in the morning execution


12.12 static files do not log logs and expire time

vim/usr/local/nginx/conf/vhost/test.com.conf //Edit the configuration file and add the following line to the server

--------------------------------------------------------------

Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $

{

Expires 7d;

Access_log off;

}

Location ~. *\. (JS|CSS) $

{

Expires 12h;

Access_log off;

}

--------------------------------------------------------------

Location matching; \ de-expires; expiration time; Access_log off does not log access logs;

/USR/LOCAL/NGINX/SBIN/NGINX-T//Check configuration for errors

/usr/local/nginx/sbin/nginx-s Reload//reload, can also restart service

Test

cd/data/wwwroot/test.com/

Ls

Vim 1.gif//write something casually

Vim 2.js //write something .

Curl-x127.0.0.1:80 Test.com/1.gif

Curl-x127.0.0.1:80 Test.com/2.js

Cat/tmp/test.com.log


Linux study notes 12 weeks three lessons (April 25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.