Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Somehow, Google has indexed my site via IP address as well as by domain. E.g., 180.10.1.1/index.php as well as www.mysite.com/index.php

I want to 301 all those ip address urls to the appropriate hostname urls, but can't figure out how to do it in nginx.conf.

Thank you for your help...

share|improve this question
    
Neither of these answers work for me with the latest version of nginx. I just end up in an infinite redirect loop. I've even tried to regex the IP hoping it would stop future requests but to no avail. –  user100531 Nov 9 '11 at 23:14
add comment

3 Answers

The above 2 answers didn't work for me either and resulted in an infinite redirect loop. Adding the ip address to my server_name worked:

server {
    listen 80;
    server_name mydomain.com www.mydomain.com 67.20x.xxx.xx;
       ...
    }
share|improve this answer
add comment

Add another server block to your config file

server {
    listen 180.10.1.1:80;
    server_name 180.10.1.1;
    rewrite .* http://www.mysite.com$request_uri permanent;
}
share|improve this answer
    
Nailed it. THANK YOU. –  Arron Dec 5 '09 at 21:05
add comment

if you have latest version of nginx:

server {
  listen 80 default;
  rewrite ^ http://mysite.com$request_uri permanent;
}
share|improve this answer
    
in this case default means bind to all ips 0.0.0.0 i think, which might give you unexpected results? –  djangofan Nov 9 '11 at 23:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.