apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-conf
data:
  nginx.conf: |
    user nobody;
    worker_processes 1;
    pid /run/nginx.pid;

    events {
      worker_connections 1024;
    }

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

      log_format json_combined escape=json
          '{'
            '"time_local":"$time_iso8601",'
            '"client_ip":"$http_x_forwarded_for",'
            '"remote_addr":"$remote_addr",'
            '"remote_user":"$remote_user",'
            '"request":"$request",'
            '"status":"$status",'
            '"body_bytes_sent":"$body_bytes_sent",'
            '"request_time":"$request_time",'
            '"http_referrer":"$http_referer",'
            '"http_user_agent":"$http_user_agent",'
            '"request_id":"$request_id"'
          '}';

      access_log /dev/stdout json_combined;

      server {
        listen 8080;
        server_name _;

        root /www;
        index index.php;
        error_page 404 /index.php;

        charset utf-8;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Content-Type-Options "nosniff";

        # [<ru>] Отдадим ассеты напрямую из файловой системы NGINX-контейнера.
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

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

        # [<ru>] Все запросы, кроме запросов на получение ассетов, отправляются на php-fpm-бэкенд.
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php-fpm.sock;
            fastcgi_param DOCUMENT_ROOT   /app/public;
            fastcgi_param SCRIPT_FILENAME /app/public/$fastcgi_script_name;
            include fastcgi_params;
        }
      }
    }
