Onto-Med / top-frontend

JavaScript based frontend of the TOP Framework
MIT License
0 stars 1 forks source link

reduce nginx log level from notice to warn #342

Closed KonradHoeffner closed 8 months ago

KonradHoeffner commented 8 months ago

Part of https://github.com/Onto-Med/top-deployment/issues/44.

KonradHoeffner commented 8 months ago

There are two config files at play here:

/etc/nginx/nginx.conf is the default configuration and contains configuration of the nginx server.

nginx.conf from the base path of this repository contains configuration of the specific web app and is copied into the /etc/nginx/conf.d/ directory, which is included from a statement of /etc/nginx/nginx.conf: include /etc/nginx/conf.d/*.conf;.

/etc/nginx/nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

I don't know if it is possible and a better solution to merge those two or if overriding the error_log statement from within the nginx.conf from this repository works as I already tried overwriting it using an env variable which didn't work, so I am not sure if the changes are worth it to try that but feel free if you want. I agree that the current way sucks because there are two different files with the same name but I'm not sure if there is a more elegant way.

/etc/nginx/nginx.conf.d/nginx.conf (after copy)

server {
  listen 80 default_server;

  root /usr/share/nginx/html;

  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";

  index index.html;

  charset utf-8;

  location / {
    try_files $uri $uri/ /index.html;
    add_header Cache-Control "no-store, no-cache, must-revalidate";
  }

  location = /favicon.ico {
    access_log off;
    log_not_found off;
  }
  location = /robots.txt {
    access_log off;
    log_not_found off;
  }

  location ~ /\.(?!well-known).* {
    deny all;
  }
}
ChristophB commented 8 months ago

The Nginx documentation is a bit confusing here.

The default setting of the error log works globally. To override it, place the error_log directive in the main (top-level) configuration context.

However, if several error_log directives are specified on the same level, the message are written to all specified logs.

I am not sure if error_log can be overridden (maybe the top level is an exception?). I will try it tomorrow and if it works, I will create another PR.

KonradHoeffner commented 8 months ago

I am not sure if error_log can be overridden (maybe the top level is an exception?). I will try it tomorrow and if it works, I will create another PR.

Good luck! Maybe this StackOverflow post can help you: https://unix.stackexchange.com/questions/769346/how-to-suppress-nginx-worker-process-notices/771151#771151 at least that shows what I tried to overwrite it which didn't work :-)

KonradHoeffner commented 8 months ago

P.S.: Or we just switch to Caddy :-)

ChristophB commented 8 months ago

P.S.: Or we just switch to Caddy :-)

As discussed recently, this would be a nice (or even better) option. But I lack the Caddy knowledge.