# ./nginx/default.conf

server {
    listen 80;
    server_name localhost;
    index index.php index.html;

    root /var/www/html/public;

    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;
    set_real_ip_from 127.0.0.1;
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;

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

    location ~ \.php$ {
        # PHP handles its own compression (App::compressResponse)
        gzip off;

        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param HTTP_X_REAL_IP $http_x_real_ip;
        fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto;
        fastcgi_param HTTP_X_FORWARDED_HOST $http_x_forwarded_host;
        fastcgi_param HTTP_X_FORWARDED_SSL $http_x_forwarded_ssl;
        fastcgi_param HTTPS $https if_not_empty;

        fastcgi_connect_timeout 60s;
        fastcgi_send_timeout 60s;
        fastcgi_read_timeout 60s;

        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

    location ~* \.(jpg|jpeg|png|gif|svg|ico|css|js|woff|woff2|ttf|eot)$ {
        gzip on;
        gzip_types text/css application/javascript image/svg+xml font/woff2;
        gzip_vary on;
        gzip_min_length 1024;
        gzip_comp_level 6;

        expires 30d;
        access_log off;
        add_header Cache-Control "public, immutable";
    }
}
