• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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