'Running If Statement in NGINX website configuration files

Im trying to use an if statement that allows me to ignore headers only when caching a request. This is the code I implemented ( on /etc/nginx/sites-available/example.com) :

if ($skip_cache = 0) {
     fastcgi_ignore_headers X-Accel-Expires Expires Cache-Control;
}

When I run a check on the configuration file's syntax, i get the following error:

nginx: [emerg] "fastcgi_ignore_headers" directive is not allowed here in /etc/nginx/sites-enabled/chartership.com:46
nginx: configuration file /etc/nginx/nginx.conf test failed

Do you guys have any suggestions to steer the implementation correctly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source