如何使用nginx强制下载js文件?

How to force download a js file using nginx?

我想强制用户从我的服务器下载 js/pac 文件,我在 nginx.conf

中设置了这些代码
    server {
    location ~ .*\.(pac|js)$ {
        add_header Content-Disposition "attachment; filename=$request_filename";
    }
}

或者像这样

    server {
    location /pacfile/ {
        types {
            application/octet-stream js;
        }
    }
}

但是none这个方法有效。为什么?

解决我的问题。 我需要设置监听端口和 server_name;

server {
    listen 80;
    server_name my.domain.com;
    location {...}
}

现在有效。