Skip to content Skip to sidebar Skip to footer

How to Setting Nginx Request Time Log Milliseconds in RHEL 7

Benefit

By enabling request time in logs you will find it easier when there is a problem with your application, and you can analyze the access log and see how long it takes to request data between servers.

Preparation

Before doing this configuration, make sure you have installed the Nginx itself, and make sure you first backup the original Nginx configuration by:

# cp /etc/nginx/nginx.conf /etc/nginx/nginx/conf.ori

Once the backup is free, you can edit the configuration.

Configure

To create an access log with request time, you have to set up the configuration of the nginx service itself. Here the default settings for nginx are usually in / etc / nginx / with the file name nginx.conf. You can edit directly with vi.

# vi /etc/nginx/nginx.conf
}
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
          '$status $body_bytes_sent $request_time "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
}

save & exit

configure of nginx request time
configure of nginx request time

After you configure it in nginx.conf, try adding main at the end of the configuration of the access log in your vhost.

# vi /etc/nginx/sites-enable/nginx-kitsake.conf]
server {
    listen  1111;
    root    "/app/kitsake/public";
    server_name kitsake;
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
    access_log /var/log/nginx/kitskae-access.log main;
    error_log /var/log/nginx/kitsake-error.log;
}

save & exit

configure of vhost request time
configure of vhost request time

After you have finished configuring it all, try to apply it by restarting the Nginx service.

# nginx -t
# systemctl restart nginx

Trying

Finally, you can test whether the configuration is running perfectly. You can hit it by hitting your server ip and application port, and you can also monitor the access log on your server to see the results:

trying to hit manual webserver with request time
trying to hit manual webserver with request time
Bangkit Ade Saputra
Bangkit Ade Saputra At the end of the day, my job involves people. we're complicated, we're always changing, we have millions of things going on in our lives, and changing jobs is always a big decision.

Post a Comment for "How to Setting Nginx Request Time Log Milliseconds in RHEL 7"