Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralphmrivera's avatar

Logging 301 records and the redirection URL in an access file

Hi everyone,

I have a question about how 301 entries are logged. A bit of background:

I created a new server in Forge and added a site. By default, NGINX logs to /var/log/nginx/access.log

In Forge, I edited the site conf to go from this:

    access_log off;
    error_log  /var/log/nginx/www.foo.com-error.log error;

to this:

    #access_log off;
    error_log  /var/log/nginx/www.foo.com-error.log error;
    access_log /var/log/nginx/www.foo.com-access.log;

At this point, I am getting a separate access log for each individual site. This is what I want, but the problem is that 301 entries are still being logged in the default access log.

For example:

This record:

06/Dec/2019:16:54:28 +0000 - 111.111.111.111 - www.foo.com - GET / HTTP/1.1 - 301 - 169 - - - Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362 - 111.111.111.111

Is being logged to /var/log/nginx/access.log instead of /var/log/nginx/www.foo.com-access.log

I'd like to do two things, but I don't know how:

  • #1 Make sure that anything related to www.foo.com is being logged to the foo.com-access file including 301 entries.

  • #2 Add a field to the log_format that shows where the request is redirecting to (not just the referrer from) in the log.

Can anyone help with this?

Thanks!

0 likes
0 replies

Please or to participate in this conversation.