


Nginx common log splitting methods nginx apache nginx php nginx rewrite
方式一: nginx cronolog日志分割配置文档,根据下面方法,每分钟分割一次NGINX访问日志。 <span>1</span>.nginx日志配置 access_log access_log /data/access_log_pipe main; <span>2</span>.先创建一个命名管道 mkfifo /www/<span>log</span>/access_log_pipe <span>3</span>.配置cronolog: nohup cat /data/access_log_pipe | <span>/usr/local</span><span>/sbin/cronolog</span> /data/<span>log</span>/domain.access<span>_</span><span>%Y</span><span>%m</span><span>%d</span><span>%H</span><span>%M</span>.<span>log</span> & <span>4</span>.启动Nginx /usr/<span>local</span>/nginx/sbin/nginx 注意: cronolog必须在nginx启动前启动 没有安装cronolog的话,需要先安装 wget http:<span>//cronolog</span>.org/download/cronolog-<span>1.6</span>.<span>2</span>.tar.gz tar zxvf cronolog-<span>1.6</span>.<span>2</span>.tar.gz cd cronolog-<span>1.6</span>.<span>2</span> .<span>/configure make make install 方式二: 定时任务中每小时添加定时任务,执行一下脚本,可以实现小时日志分割 log_dir="/var</span><span>/log/nginx</span><span>" date_dir=`date +<span>%Y</span>/<span>%m</span>/<span>%d</span>/<span>%H</span>` /bin/mkdir -p <span>${log_dir}</span>/<span>${date_dir}</span> > /dev/null 2>&1 /bin/mv <span>${log_dir}</span>/access.log <span>${log_dir}</span>/<span>${date_dir}</span>/access.log kill -USR1 `cat /opt/nginx/logs/nginx.pid` 方式三: 使用logrotate做nginx日志轮询 logrotate看名字就知道是专门做日志轮询的,只把任务配置放在/etc/logrotate.d/下,任务就会自动完成,而且无需安装,系统自带,比较推荐使用. vi /etc/logrotate.d/nginx /usr/local/nginx/logs/www.willko.cn.log /usr/local/nginx/logs/nginx_error.log { notifempty daily sharedscripts postrotate /bin/kill -USR1 `/bin/cat /usr/local/nginx/nginx.pid` endscript } 多个日志以空格分开, notifempty 如果日志为空则不做轮询 daily 每天执行一次 postrotate 日志轮询后执行的脚本 这样,每天都会自动轮询,生成nginx.log.1-n 后话: 用Jmeter对方法一进行了测试,新建线程组:线程数200,循环150,新建http请求,请求nginx上的图片,请求30000次,失败326次,后台形成5个文件,行数如下: 2868 access_201112182030.log 7777 access_201112182031.log 7626 access_201112182032.log 7873 access_201112182033.log 3530 access_201112182034.log 29674 total 并没有因为切分文件而丢失日志。</span>
The above introduces the common log splitting methods of Nginx, including nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".
