kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: tarroja
data:
  nginx.conf: |
    events {
      worker_connections  4096;
    }

    http {
      include mime.types;

      log_format timed_combined '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $body_bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '$request_time $upstream_response_time $pipe';


      server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # Set nginx to serve files from the shared volume!
        root /var/www/lifetrack/public;

        client_max_body_size 25m;
        fastcgi_read_timeout 600;
        proxy_connect_timeout 600;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        send_timeout 600;

        server_name _;
        index index.php index.html;

        # pass user's real ip
        set_real_ip_from 0.0.0.0/0;
        real_ip_header X-Real-IP;
        real_ip_recursive on;

        location /nginx_status {
          # Turn on stats
          stub_status on;
          access_log  off;
          # access to this route will be disable (hidden behind basic http auth) at the ingress
        }

        location / {
          try_files $uri $uri/ /index.php?$query_string;

          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

          # nginx:alpine symlinks this to /dev/stdout
          access_log /var/log/nginx/access.log timed_combined;
        }

        location ~ \.php$ {
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param REMOTE_ADDR $http_x_real_ip;

          # nginx:alpine symlinks this to /dev/stdout
          access_log /var/log/nginx/access.log timed_combined;
        }
      }
    }
