1

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.

  • How are you using the $new variable in both configurations? – Richard Smith Oct 15 '18 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 '18 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. – Gerald Schneider Oct 15 '18 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. – Richard Smith Oct 15 '18 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 '18 at 8:24
1

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.