0

I configured nginx to act as a reverse proxy for Blynk's API since the visualization tool I'm using requires me to use https and they just support http.

Everything works fine, but since i need to download historical data in CSV format and they just provide gzipped csv I was trying to configure nginx to decompress csv.gz files on-the-fly into plain csv files. Turns out that by adding the Content-Encoding header the csv data magically appears on my REST client. So I was trying to configure nginx to add the header only on specific URLs. The URLs that need the header are those with the following format: https://blynk-api.my-domain.com/AUTH_TOKEN/data/PIN_CODE. I tried to use the following regex, but I can't understand what's wrong with that. I hope that someone can help me :)

server {

    listen 127.0.0.1:4443 ssl http2;
    listen [::]:443 ssl http2;
    server_name blynk-api.my-domain.com;

    ssl_certificate /etc/letsencrypt/live/blynk-api.my-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/blynk-api.my-domain.com/privkey.pem;

    ssl on;

    access_log /var/log/nginx/blynk-api.access.log;

    location / {

            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

            if ($uri ~ "(.*)/data/(.*)"){
                 add_header Content-Encoding gzip;
            }

            proxy_buffering off;
            proxy_pass http://blynk-cloud.com:80;

    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.