upstream parsley_app {
    ip_hash;
    server app;
}

server {
    listen 80;
    root /parsley/public;

    location / {
        try_files $uri @rails;
    }

    location ~ ^/(assets|packs)/ {
        try_files $uri @rails;
        gzip_static on;
        expires 1y;
        add_header Cache-Control public;
        add_header ETag "";
        break;
    }

    location /cable {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://parsley_app/cable;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location @rails {
        proxy_pass http://parsley_app;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
