D
D
Dmitry2018-04-12 14:39:55
Nginx
Dmitry, 2018-04-12 14:39:55

nginx. access_log in location with try_files how?

Quite a stupid question, but I don't know how to do it.
There are customized logs for everything nginx. But I want all requests that arrive in /login.html to be logged with a specific format (log the request body) to a specific file.
If there are no try_files in location /login.html, then requests arrive and are logged, but naturally with a 404 error
. login.html does not exist (this is a virt. page in yii) and access_log stops working in this location...
How to write logs of a certain format in only one location correctly?

http {
        log_format  main    '$remote_addr - $remote_user [$time_local] $scheme $server_name "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for" $request_time "$http_cf_ray" "$ssl_protocol/$ssl_cipher"';

        log_format postdata '$remote_addr - $remote_user [$time_local] $scheme $server_name "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for" $request_time "$http_cf_ray" "$ssl_protocol/$ssl_cipher" '
                            '"$request_body"';
        access_log syslog:server=unix:/dev/log,nohostname,facility=local7,tag=nginx_access,severity=info main;
        error_log syslog:server=unix:/dev/log,nohostname,facility=local7,tag=nginx_error error;
        # * * * 
server {
    # * * * 
    location /login.html {
        try_files $uri $uri/ /index.php?$args;
        access_log /var/log/nginx/login_html_postdata.log postdata;
    }
    # * * * 
    location ~ \.php$ {
        # fastcgi
        include conf.d/php7.1-fpm.inc;
    }
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2018-04-12
@helldweller

More or less like this

location /login.html {
    rewrite ^ /index.php break;
    include conf.d/php7.1-fpm.inc;
    access_log /var/log/nginx/login_html_postdata.log postdata;
}

The point is to stay at this location

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question