worker_processes auto;

error_log  /var/log/nginx/error.log warn;
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;

    keepalive_timeout  65;

    set_real_ip_from  10.0.0.0/8;
    set_real_ip_from  172.16.0.0/12;
    set_real_ip_from  192.168.0.0/16;
    real_ip_header    X-Real-IP;

    upstream php-handler {
        server CP_HOST_BACK:9000;
    }

    server {
        listen 80;

        root /var/www/html;

        index index.php index.html index.htm;

        client_max_body_size 1G;
        fastcgi_buffers 64 4K;

        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_types application/atom+xml application/javascript audio/mpeg application/rss+xml image/bmp image/png image/jpeg image/webp image/svg+xml image/x-icon video/mp4 text/css text/plain text/html;

	location ~ /.*\.(png|ico|txt|js|js\.map)$ {
            try_files $uri =404;
        }

        location ~ /(assets|media)/.*$ {
            try_files $uri =404;
        }

        location /.well-known/GDPR.yml {
            try_files $uri =404;
        }

        location / {
            fastcgi_param SCRIPT_FILENAME /opt/castopod/public/index.php;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_pass php-handler;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_param SCRIPT_FILENAME /opt/castopod/public/$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_pass php-handler;
        }
    }
}
