InsideDarkWeb.com

NGINX content disposition attachment not working on subdomain

Primary domain – imagecompressor.io, subdomain – dev.imagecompressor.io

Content disposition does not seem to be working for the subdomain. curl returns a 200 OK for both, but the file is only downloaded for the primary domain. For the subdomain the request get forwarded to the reactjs frontend application.

https://imagecompressor.io/images/Logo.png – works
https://dev.imagecompressor.io/images/Logo.png – does not work

NGINX configuration – domain

server {

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/imagecompressio-js/serve;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name imagecompressor.io;
    # error_log /var/log/nginx/error.log debug;
    
    location /images {
        alias /var/www/images;
                add_header Last-Modified $date_gmt;
                add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
                if_modified_since off;
                expires off;
                etag off;
                add_header Content-disposition "attachment; filename=$1";
    }

    location /files {
        alias /var/www/files;
        expires 3d;
        add_header Cache-Control public;
        add_header Content-disposition "attachment; filename=$1";
    }
    location ^~  /blog {
        root /var/www/;
        try_files $uri $uri/ =404;
    }
    location = /blog/mozjpeg-guide/compress {
        return 301 /blog/mozjpeg-guide;
    }
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri /index.html =404;
        expires -1;
    }

     location ~* .(?:css|js)$ {
        access_log        off;
            log_not_found     off;
        add_header        Cache-Control "no-cache, public, must-revalidate, proxy-revalidate";
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ .php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
    #   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /.ht {
    #   deny all;
    #}

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/imagecompressor.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/imagecompressor.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

NGINX configuration – subdomain

server {

    root /var/www/imagecompressio-js/serve;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name dev.imagecompressor.io;
    error_log /var/log/nginx/error.log debug;
    
    location /images {
        alias /var/www/images;
        add_header Last-Modified $date_gmt;
            add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
            if_modified_since off;
            expires off;
            etag off;
        add_header Content-disposition "attachment; filename=$1";
    }

    location /files {
        alias /var/www/files;
        expires 3d;
        add_header Cache-Control public;
        add_header Content-disposition "attachment; filename=$1";
    }
    location ^~  /blog {
        root /var/www/;
        try_files $uri $uri/ =404;
    }
    location = /blog/mozjpeg-guide/compress {
        return 301 /blog/mozjpeg-guide;
    }
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri /index.html =404;
        expires -1;
    }

     location ~* .(?:css|js)$ {
        access_log        off;
            log_not_found     off;
        expires 30d;
        add_header        Cache-Control "no-cache, public, must-revalidate, proxy-revalidate";
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ .php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
    #   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /.ht {
    #   deny all;
    #}

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/dev.imagecompressor.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dev.imagecompressor.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

curl output

dev.imagecompressor.io

curl --head https://dev.imagecompressor.io/images/Logo.png

HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Tue, 21 Jul 2020 21:10:07 GMT
Content-Type: image/png
Content-Length: 6865
Connection: keep-alive
Last-Modified: Tuesday, 21-Jul-2020 21:10:07 GMT
Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0
Content-disposition: attachment; filename=
Accept-Ranges: bytes

imagecompressor.io

curl --head https://imagecompressor.io/images/Logo.png

HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Tue, 21 Jul 2020 21:15:00 GMT
Content-Type: image/png
Content-Length: 6865
Connection: keep-alive
Last-Modified: Tuesday, 21-Jul-2020 21:15:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0
Content-disposition: attachment; filename=
Accept-Ranges: bytes

Exact same. Can’t figure out what’s the issue here.

Server Fault Asked by Aseem Gautam on November 14, 2021

1 Answers

One Answer

It seemed like a cache issue but clearing the cache did work for a few downloads. Root cause came to be service worker being enabled on the subdomain front-end. Disabling it made the issue go away.

enter image description here

Answered by Aseem Gautam on November 14, 2021

Add your own answers!

Related Questions

Zabbix sensor ‘no data’

1  Asked on February 6, 2021 by jakub-kuszneruk

   

How to enable Ookla script to start automatically after server reboot?

1  Asked on February 5, 2021 by mangaldeep-dey

   

iptables port redirect with Docker

2  Asked on February 5, 2021 by jamescun

   

Where to securely deploy Citrix Netscaler?

1  Asked on February 4, 2021 by user54507

   

Kubernetes: How to mount volumes into Windows pods?

1  Asked on February 4, 2021 by rabejens

   

FTP file transfer, loop through a directory and copy old files

1  Asked on February 4, 2021 by mich-dart

   

df differs from du a lot, nfsd service seems matter

0  Asked on February 4, 2021 by guangyu-wu

       

How to run DBCC CHECKDB with both REPAIR_ALLOW_DATA_LOSS and NOINDEX

1  Asked on February 3, 2021 by walter-zydhek

 

Is it possible to configure a reverse VPN tunnel?

4  Asked on February 3, 2021 by nikita240

     

Meaning of the buffers/cache line in the output of free

3  Asked on February 2, 2021 by muahmmad-zeeshan

       

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.