log_format compression '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for" '
                       '$request_time $upstream_response_time $pipe $upstream_cache_status';
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
upstream app_backend {
    server 127.0.0.1:8032;
}
server {
    listen 80;
    listen [::]:80;

    root /var/www/public;
    server_name localhost;
    index index.php index.html;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";

    client_max_body_size 250m;
    charset utf-8;
    server_tokens off;
    keepalive_timeout 75;
    tcp_nopush on;
    tcp_nodelay on;
    sendfile on;

    #access_log /var/www/deployment/nginx/logs/access.log compression;
    #error_log /var/www/deployment/nginx/logs/error.log;
    error_log /dev/stdout info;
    access_log  /dev/stdout main;

    location /index.php {
        try_files /not_exists @octane;
    }

    location / {
        try_files $uri $uri/ @octane;
    }

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

    error_page 404 /index.php;

    location @octane {
        set $suffix "";

        if ($uri = /index.php) {
            set $suffix ?$query_string;
        }

        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header SERVER_PORT $server_port;
        proxy_set_header REMOTE_ADDR $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_pass http://app_backend$suffix;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        expires max;
        add_header Cache-Control public;
        log_not_found off;
        access_log off;
        error_log off;

        # Some browsers still send conditional-GET requests if there's a
        # Last-Modified header or an ETag header even if they haven't
        # reached the expiry date sent in the Expires header.
        add_header Last-Modified "";
        add_header ETag "";
        break;
    }

    location ~ /\. {
        log_not_found off;
        deny all;
    }
}
