Masking link with a 302 redirect through nginx not working

I’m trying to mask an affiliate link, so I want to have a 302 redirect through nginx

I want to redirect all /go links to the respective affiliate link, so all link redirects would be like mydomain.com/go/affiliate redirects to > https://www.affiliatelink.com

Right now this is what I have

location /go {
                rewrite ^/affiliate$ https://www.affiliatelink.com redirect; 
     }

I have tried everything and I cannot seem to be able to get it to work. Is there a specific file I need to do it on?

I have already tried both /sites-enabled/default and /conf.d/nginx.conf