Wednesday, July 8, 2020

Find Size of all files with certain extensions

You can find the size with this find command:


find . -iregex ".*\.\(jpg\|gif\|png\|jpeg\)"  -exec du -ch {} + | grep total$


iregex means case-insensitive.

Thursday, May 7, 2020

Use different backend based on HTTP Header in Nginx

To do this, you can use this configuration:


upstream production {
     server 10.0.0.1:80;
}

upstream stage {
     server 10.0.0.2:80;
}


# map to different upstream backends based on header
map $http_x_which_deployment $pool {
     default "production";
     stage "stage";
}

server {
     listen 80;
     server_name _;
     location / {
            proxy_pass http://$pool;
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $http_true_client_ip;
            proxy_set_header Host $host;
            proxy_connect_timeout       600;
            proxy_send_timeout          600;
            proxy_read_timeout          600;
            send_timeout                600;     }
}



Then if you add "X-Which-Deployment" header and set it to "stage", you will be pointed to "Stage Server" (here 10.0.0.2).

Wednesday, April 8, 2020

Elasticsearch flood stage disk watermark error


If your disk is full, you must first empty it and then run these two curl commands:


curl -XPUT -H "Content-Type: application/json" http: //localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'


curl -XPUT -H "Content-Type: application/json" http: //localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}