Domain redirection problem in nginx

August 16, 2013 3.7k views
Hi, I have 2 domains (domain used here is just example), helloworld.my and helloworld.com.my I want to redirect: A. helloworld.my to www.helloworld.com.my B. www.helloworld.my to www.helloworld.com.my I managed to redirect the A But i cannot make the B works. Below is my nginx config for hellworld.my server { listen 80; server_name helloworld.my; return 301 http://www.helloworld.com.my$request_uri; } server { listen 80; server_name www.helloworld.my; return 301 http://www.helloworld.com.my$request_uri; } Anyone can help me?
4 Answers
Do you have valid DNS records for www.helloworld.my?

www CNAME @

OR

www A your.ip.address
damn! i forgot that, let me put that first and test it again, thanks kamal!
Hi, Kamal

I have same problem to I want redirect www.mydomain.com to mydomain.com
In my digitalocean DNS I have CNAME www @

In my nginx conf ;

server {
listen 8080;
server_name www.myadomain.com;
return 301 $scheme://mydomain.com$request_uri;
}


server {
listen 8080;
server_name mydomain.com;
.....
}

What I missing configuration here?


@johanrube: Try including the port in the redirect, does that fix it?
Have another answer? Share your knowledge.