Issue Add item to log_format

karyo

New Pleskian
Server operating system version
18.04.6 LTS
Plesk version and microupdate number
18.0.44
Hello
I wanted to add the following to the log_format in nginx and Apache.
But I do not know how it is possible
Can you help me?
br-real-ip X-Real-Ip X-Forwarded-For

Nginx:
log_format test1 ‘… $http_x_real_ip $http_br_real_ip $http_x_real_ip…’

Apache:
LogFormat " %h %l %u %t "%r" %>s %b %{X-Forwarded-For} %{X-Real-Ip} %{br-real-ip}i" test1
 
You can change LogFormat for Apache with the following steps
  1. Create /usr/local/psa/admin/conf/templates/custom/ custom template folder:
    Code:
    # mkdir -p /usr/local/psa/admin/conf/templates/custom/
  2. Copy /usr/local/psa/admin/conf/templates/default/server.php into custom template folder:
    Code:
    # cp -a /usr/local/psa/admin/conf/templates/default/server.php /usr/local/psa/admin/conf/templates/custom/server.php
  3. Open /usr/local/psa/admin/conf/templates/custom/server.php file using any text editor.
  4. Change log format in custom template in the following section according to Apache documentation:
    Code:
    <IfModule mod_logio.c>
    LogFormat "<?php echo $VAR->server->webserver->apache->pipelogEnabled ? '%v@@%p@@' : ''?>%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
    </IfModule>
    <IfModule !mod_logio.c>
    LogFormat "<?php echo $VAR->server->webserver->apache->pipelogEnabled ? '%v@@%p@@' : ''?>%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
    </IfModule>
  5. Check that the modified template is a valid PHP file:
    Code:
    # php -l /usr/local/psa/admin/conf/templates/custom/server.php
    No syntax errors detected in /usr/local/psa/admin/conf/templates/custom/server.php
  6. Regenerate server configuration based on the new template:
    Code:
    # plesk sbin httpdmng --reconfigure-server
Note: customizing Apache access log format may break webstatistics calculation as webstat tools (Webalizer and Awstats) use CLF (Common Log Format) when each line in a file stored in the Common Log Format has the strictly defined syntax.
More information can be found in Plesk and Apache documentation:
Changing Virtual Hosts Settings Using Configuration Templates
Apache Log Files
 
For nginx you may try to uncomment log_format directive in "/etc/nginx/nginx.conf" and add there your options
Code:
log_format  test1 ‘… $http_x_real_ip $http_br_real_ip $http_x_real_ip…’;
Please be aware about mentioned above consequences of changing log format.
 
You can change LogFormat for Apache with the following steps
  1. Create /usr/local/psa/admin/conf/templates/custom/ custom template folder:
    Code:
    # mkdir -p /usr/local/psa/admin/conf/templates/custom/
  2. Copy /usr/local/psa/admin/conf/templates/default/server.php into custom template folder:
    Code:
    # cp -a /usr/local/psa/admin/conf/templates/default/server.php /usr/local/psa/admin/conf/templates/custom/server.php
  3. Open /usr/local/psa/admin/conf/templates/custom/server.php file using any text editor.
  4. Change log format in custom template in the following section according to Apache documentation:
    Code:
    <IfModule mod_logio.c>
    LogFormat "<?php echo $VAR->server->webserver->apache->pipelogEnabled ? '%v@@%p@@' : ''?>%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
    </IfModule>
    <IfModule !mod_logio.c>
    LogFormat "<?php echo $VAR->server->webserver->apache->pipelogEnabled ? '%v@@%p@@' : ''?>%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" plesklog
    </IfModule>
  5. Check that the modified template is a valid PHP file:
    Code:
    # php -l /usr/local/psa/admin/conf/templates/custom/server.php
    No syntax errors detected in /usr/local/psa/admin/conf/templates/custom/server.php
  6. Regenerate server configuration based on the new template:
    Code:
    # plesk sbin httpdmng --reconfigure-server
Note: customizing Apache access log format may break webstatistics calculation as webstat tools (Webalizer and Awstats) use CLF (Common Log Format) when each line in a file stored in the Common Log Format has the strictly defined syntax.
More information can be found in Plesk and Apache documentation:
Changing Virtual Hosts Settings Using Configuration Templates
Apache Log Files

For nginx you may try to uncomment log_format directive in "/etc/nginx/nginx.conf" and add there your options
Code:
log_format  test1 ‘… $http_x_real_ip $http_br_real_ip $http_x_real_ip…’;
Please be aware about mentioned above consequences of changing log format.


Thank you very much for your help.
Is there a way to apply this log to only one site and not the entire website?
 
Is there a way to apply this log to only one site and not the entire website?
You can try to specify it in Additional Apache/nginx directives in Apache & nginx Settings for your domain, but note that not all directives are allowed for applying there.
 
Back
Top