nginx configuration generates logs by day in Linux environment

Add the following configuration in nginx.conf as shown in the figure:

    map $time_iso8601 $logdate {
        '~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
        default    'date-not-found';
    }
    access_log logs/access-$logdate.log;

Then: wq save and exit

Modify the permissions of the logs folder (change to your own location, mine is placed under /opt/nginx):

chmod -R 777 /opt/nginx/logs

Finally, go back to the niginx/sbin directory and reload the configuration file:

 ./nginx -s reload

In this way, the configuration will take effect. Visit the relevant webpage, generate the log and then take a look:

You can see that it has been generated according to the date.

Guess you like

Origin blog.csdn.net/qq_16382227/article/details/124905374