0

i created an azure vps and redirected my domain to the dns . However i now have 2 domains pointing to my website which is not good for seo.

example.com

yyy..cloudapp.azure.com

I am using nginx web server and i want to permanently redirect all *.cloudapp.azure.com to domain.com

I tried :

server {
    listen 80;
    server_name yyy.westeurope.cloudapp.azure.com www.yyy.westeurope.cloudapp.azure.com; 
    rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}

server {
    server_name domain.com www.example.com;
    .....

}

It is not working . I restarted nginx server eaach time

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
Sam.tuver
  • 679
  • 2
  • 9
  • 19

1 Answers1

1

server_name supports suffix matches using .westeurope.cloudapp.azure.com syntax.

Try below:

server {
    listen 80;
    server_name .westeurope.cloudapp.azure.com; 
    rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}

Also, you could refer to this answer on SO.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • @Sam.tuver I modify the configuration in `/etc/nginx/sites-available/default`. It works me fine. – Shui shengbao Aug 16 '17 at 10:13
  • When you access your web `yyy.westeurope.cloudapp.azure.com` the url rewrite to `http://www.example.com`? – Shui shengbao Aug 16 '17 at 10:14
  • 1
    Thanks its working now . However when i use : yyy.westeurope.cloudapp.azure.com/page3 . It works instead of redirecting to the new site . How to fix this ? – Sam.tuver Aug 16 '17 at 15:41
  • @Sam.tuver Maybe this [link](https://www.digitalocean.com/community/tutorials/how-to-create-temporary-and-permanent-redirects-with-nginx#example-1-—-moving-to-a-different-domain) is helpful. – Shui shengbao Aug 17 '17 at 01:21