One of the right method:
map $request $logfile{ ~*filename\.php 0; default 1; } server{ access_log /pathtologfilename.log combined if=$logfile; }
map variable should be outside the server. Do not forget to add combined keyword.