We' ve currently changed all the structure of our website and moved it from Apache to Nginx. For many links we've set properly 301 redirects, still many pages that don't exist anymore are returning 404 errors. We've a specific list of links that we need to return 410 errors but we don't know how to do that on nginx. Can someone help us on this matter please? Thanks in advance!
Asked
Active
Viewed 5,676 times
3
-
Nothing as we don't know what to do in these kind of situations in nginx – Lightbox Nov 10 '15 at 09:19
-
It would be useful to see the nginx configuration that generates the 301 redirects and an example of a link that you would like to return 410 instead. – Richard Smith Nov 10 '15 at 11:04
-
@RichardSmith For redirects we are simply using a plugin on Wordpress called Redirection. An example would be: http://myartguides.com/categories/art/item/2894-michael-craig-martin-in-hong-kong – Lightbox Nov 10 '15 at 11:11
-
@Lightbox edit your post and add config to it. No need for external (broken) links. – Alexey Ten Nov 10 '15 at 11:17
-
@AlexeyTen We're not sure we've understood...many pages that we had are gone and we don't want to have them anymore... – Lightbox Nov 10 '15 at 11:24
1 Answers
4
A map might work well here:
http {
# ...
map $uri $gone {
default 0;
~^/old-link1 1;
~^/another-obsolete-link 1;
# consider an included file for these
}
server {
if ($gone) {
return 410;
}
# ...
}
}

Cole Tierney
- 9,571
- 1
- 27
- 35
-
Do we need to create an include folder where to put our list of links file? Do we need to create a custom 410 page too? – Lightbox Nov 16 '15 at 09:37
-
Included files are relative to the nginx folder. You could add a folder for your included files then use: `include folder/redirects.conf;` You could create a custom 410 page if you want, but I don't think it's mandatory. – Cole Tierney Nov 16 '15 at 23:07
-
We've tried but it's not working...we've added the map to nginx.conf file. Was it the right file? Any idea? – Lightbox Nov 18 '15 at 14:03
-
The map should be outside the server block at the http level. Can you post a sample of what you tried that didn't work? – Cole Tierney Nov 19 '15 at 00:08
-
We put it at the http level in the nginx.conf file...sorry but we don't know how much nginx work so what you mean by outside the server block? – Lightbox Nov 19 '15 at 08:36
-
I've added some context to illustrate the location of the map with respect to the http block. By outside the server block, I mean: `server { # the map should not be in here }` – Cole Tierney Nov 20 '15 at 00:03
-
It's what we did...we've already put it inside the http block...is the file nginx.conf the correct one? – Lightbox Nov 20 '15 at 09:04
-