Adding Errors Logs to Nginx Virtual Host Configuration file

Author: Al-mamun Sarkar Date: 2020-04-14 08:24:12

Adding Errors Logs to Nginx Virtual Host Configuration file. The following code shows how to add acess_log and error_log to the virtual host.

 

Edit artofcse.local.conf and add the following codes:

vim /etc/nginx/conf.d/artofcse.local.conf

 

server {
        listen 80 default_server;
        server_name artofcse.local www.artofcse.local;
        index index.html index.htm index.php;
        root /var/www/artofcse.com;

        access_log /var/log/nginx/artofcse.local.access.log;
        error_log /var/log/nginx/artofcse.local.error.log;

        location / {
                try_files $uri $uri/ =404;
                
                # Remove from everywhere index.php
                if ($request_uri ~* "^(.*/)index\.php(/?)(.*)") {
                     return 301 $1$3;
                }
        }

        location /images {
                autoindex on;
                access_log /var/log/nginx/artofcse.local.images.access.log;
                error_log /var/log/nginx/artofcse.local.images.error.log;
        }

        error_page 404 /404.html;
        location = /404.html {
                internal;
        }
}

 

Test Nginx configuration:

nginx -t

 

Restart Nginx Server:

systemctl reload nginx