2

I am moving my old Url's to the new one (it is more than 50) so I have placed the URLs in a file but the redirection is not happening.

map_hash_max_size 262144;
map_hash_bucket_size 262144;

map $uri $new {
    include /etc/nginx/maps/redirect_example_com.map;
}


if ($new) {
         rewrite ^ $new redirect;
        }

and below URL is in the file redirect_example_com.map

/wp/articles  /aricles;

The same configuration is using in another virtual host which is working fine.

#map_hash_max_size 262144;
#map_hash_bucket_size 262144;


map $uri $new {
    include /etc/nginx/maps/redirect_hello_com.map;
}
 if ($new) {
         rewrite ^ $new redirect;
        }

Here I am not using the bucket size.

8
  • How are you using the $new variable in both configurations? Oct 15, 2018 at 8:14
  • @RichardSmith Yes, I am using the ($new) variable and edited the question. hello.com is working fine but example.com is not working.
    – Linuxian
    Oct 15, 2018 at 8:16
  • what is not working? What is the error you experience? You have a typo in your .map file (aricles -> articles), if that's not a typo in this question only it will most probably an issue. Oct 15, 2018 at 8:21
  • Are these two virtual hosts in the same instance of nginx? The map directive is in the http block and would need to use unique variable names, e.g. $new1 and $new2. Oct 15, 2018 at 8:23
  • I have commented hash bucket size in hello.com. But if I comment the hash bucket size in example.com nginx is giving the error. nginx: [emerg] could not build map_hash, you should increase map_hash_bucket_size: 64,
    – Linuxian
    Oct 15, 2018 at 8:24

1 Answer 1

2

The map directive is placed within the http block of an Nginx configuration. And although you may separate your configuration into separate files, Nginx interprets then as a single contiguous document.

So your configuration looks like this:

http {
    map $uri $new { ... }
    server {
        if ($new) { ... }
    }
    map $uri $new { ... }
    server {
        if ($new) { ... }
    }
}

You must rename one of your $new variables to something unique. See this document for more.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .