server {
    listen 80;
    listen 443 default_server ssl;

    ssl_certificate    /etc/nginx/ssl/server.crt;
    ssl_certificate_key    /etc/nginx/ssl/server.key;

    root {{ app_base }}/www/web;
    index index.php;

    server_name localhost;

    add_header X-XSS-Protection 1;
    add_header X-Content-Type-Options nosniff;
    add_header Referrer-Policy no-referrer-when-downgrade;

    access_log {{ app_base }}/www_tmp/access.log;
    error_log {{ app_base }}/www_tmp/error.log;
    
    client_max_body_size 50M;

    location / {
        try_files $uri @clean_url;
    }

    location @clean_url {
        rewrite ^(.*)$ /index.php last;
    }

    location ~ \.php$ {
        fastcgi_hide_header Cache-Control;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME {{ app_base }}/www/web$fastcgi_script_name;
        include fastcgi_params;

        fastcgi_read_timeout 1800;
    }

    # Reverse proxy all possible radio listening ports (8000, 8010...8480, 8490)
    location ~ ^/radio/(8[0-4][0-9]0)(/?)(.*)$ {
        proxy_buffering           off;
        proxy_ignore_client_abort off;
        proxy_intercept_errors    on;
        proxy_next_upstream       error timeout invalid_header;
        proxy_redirect            off;
        proxy_connect_timeout     60;
        proxy_send_timeout        21600;
        proxy_read_timeout        21600;

        proxy_set_header Host localhost:$1;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_pass http://127.0.0.1:$1/$3?$args;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}
