First of all, I'm using Nginx 1.12.1. I want to accomplish the following thing:
- I have a list of urls, every url should return 410 for SEO purposes
- I want to include this list as a map in my nginx config (because it's a really long list)
- The 410 should be customized and look like the 404 page (for humans accidentally going there)
Relevant config snippet:
map $uri $gone {
include gone.map;
}
server {
...
error_page 410 /410.html;
# works
location ~^/gone-location-1 {
return 410;
}
# doesn't work
if ($gone) {
return 410;
}
location / {
root /app/public/;
}
}
gone.map:
~^/gone-location-2 1;
In both cases i'm doing the return 410, but the result is different. In the "doesn't work" case nginx only shows the 410 default page, while in the "works" case, it will return 410.html. In both cases, nginx correctly returns a status code of 410.
Why does this happen? I really like the idea of the map file, and i don't want to create 250 locations to make this work. Any ideas on how to accomplish this?
Edit: I just tried one more thing. I get the exact same result with 404 instead of 410.