implementation of access.log with if condition

Igor A. Ippolitov iippolitov at nginx.com
Mon Jul 31 10:16:16 UTC 2017


Hello,

As far as I know, it's impossible using Nginx.
But you can archive the same result using only 'access_log' statement 
into 'permanent' location.
Just mount your external drive 'nginx' directory over /var/log/nginx like:
     mount -o bind /externalhdd/log/nginx/ /var/log/nginx/

If it is unsuitable for you to 'hide' whole directory, you can create
a subdirectory for your logs and bind external hdd dir there:
     mount -o bind /externalhdd/log/nginx/ /var/log/nginx/mysitelogs/

Hope this helps.

On 31.07.2017 12:35, lifeisjustabout wrote:
> Hi I would like to implement if condition on access and error log. Prior to
> nginx restart I want nginx to look for first log path location eg.
> /externalhdd/log/nginx/example.com_access.log, if log doesn't exist use
> second path which is  /var/log/nginx/example.com_access.log I have given
> like my example.  I guess I need some if conditions or something.
>
> server {
>      listen       80;
>      server_name  example.com;
>      root         /var/www/example.com/public_html;
>      index        index.php;
>      IF ACCESS LOG EXIST USE THIS PATH
>      access_log
> /externalhdd/log/nginx/example.com/logs/example.com_access.log;
>      IF ACCESS LOG DOESN'T EXIST USE THIS PATH
>      access_log   /var/log/nginx/example.com/logs/example.com_access.log;
>
>
>      error_log    /var/www/example.com/logs/example.com_error.log error;
>
>      location / {
>          index index.php index.html;
>      }
>
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,275761,275761#msg-275761
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx




More information about the nginx mailing list