can someone tell me the location of access.log for nginx?

Posted November 25, 2015 295.8k views

can someone tell me where is the location of access.log file? i need to check every page thats been generating by my visitors. can that be done by access.log file? my server is nginx by the way.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
6 answers


The location of your access.log file should be defined in your /etc/nginx/nginx.conf file or your site configuration file within your server block. By default, this would be in /etc/nginx/sites-available.

Look for the access_log directive.

If it has not been defined, you can define it using the snippet below (for simplicity, this should go in /etc/nginx/nginx.conf):

log_format compression '$remote_addr - $remote_user [$time_local] '
                       '"$request" $status $bytes_sent '
                       '"$http_referer" "$http_user_agent" "$gzip_ratio"';

access_log /path/to/access.log compression buffer=32k;

… just make sure you change the last line and set /path/to/access.log to an actual path.

You don’t need to create the access.log file, NGINX will do this for you automatically, though the directories in the path must exist, so if the path you choose does not exist, you’ll need to create it before restarting NGINX.

After any/all changes to configuration files:

service nginx reload

… so that the changes will take effect.

That said, the access.log file won’t tell you anything about pages that have been generated (as in created). What it will tell you (referencing the snippet above) is the IP Address, Time of Request, Path Requested, Status of Request, Size of Request, the Request Referrer, User Agent (i.e. web browser) and whether the request was compressed (via GZIP).

Outside of that scope, logging page creation would be the responsibility of your application, if pages are being created via the script. This would either be the result of custom code or an already available option.

NGINX will give you information on the request, though it’s not meant to be a all-inclusive logging solution.

  • @jtittle
    thanks a lot.

    just to confirm. ill past the above snippet in /etc/nginx/nginx.conf

    and there wont be any (;) after this 2 lines??

    log_format compression '$remote_addr - $remote_user [$time_local] '
                                              '"$request" $status $bytes_sent '
    edited by asb
    • i did paste that snippet in /etc/nginx/nginx.conf and restarted nginx. but still noting :(

    • @newbie - Correct :-). Spacing doesn’t really matter to NGINX, so we’re able to break lines, such as that one, over multiple lines without any issues and without having to specifically tell NGINX that we’re breaking the lines. NGINX will process that as if it was a single line (and you could convert it to a single line, though it’s often broken down to prevent the definition from running off the page in your editor :-) ).

      To NGINX, this:

      include                                                /path/to/file;

      is the same as:

      include /path/to/file;

      As long as the directive is correct and the line ends with a ;, there should be no issues.

      That said, did you modify the path as noted in the comment? If you did a copy & paste verbatim, then one of two things will happen:

      1). The path /path/to/ was created and access.log is inside it or;

      2). The access.log file simply won’t be created at all.

      Please verify this first. If you did change the path as noted, please post a copy of your nginx.conf file as well as a copy of your website configuration server block (which should be in /etc/nginx/sites-available/.

      There has to be something else wrong as:

      1). If NGINX couldn’t create the file, and you defined it, NGINX should fail to start/restart.
      2). Even without the directive, NGINX should log to a pre-defined location which is often /var/log or /var/log/nginx.

use this command: sudo tail -f /var/log/nginx/error.log


works with sudo nano /var/log/nginx/access.log