I need to rewrite url when users access specific domain with root (aka /) url. So far I have:
server {
  listen 80;
  server_name name1.com name2.com;
  location = / {
    # Well, I need this only for NAME2.COM (it should not rewrite NAME1.COM)
    rewrite name2.com/users/sign_in
  }
}
How do rewrite only for NAME2.COM. Sometimes NGINX syntax makes my stack overflow. Please help.
You should split your server block. See: http://wiki.nginx.org/Pitfalls
server {
  listen 80;
  server_name name1.com;
  location = / {
    # no rewrite here
  }
}
server {
  listen 80;
  server_name name2.com;
  location = / {
    # your rewrite here
  }
}
                        You'd use if, like this:
server {
  listen 80;
  server_name name1.com name2.com;
  location = / {
    if ($host = name2.com) {
      rewrite ^ /users/sign_in last;
    }
  }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With