1

Rewriting www to non-www is not working.

The domain.com URL works but www.domain.com gives the following error "Problem loading page - Mozilla Firefox - Server not found". I've cleared FF Cache, etc.. IE, says, Internet Explorer cannot display the webpage.

I tried the following configuration and all other rewrite examples from other tutorials, including the nginx documentation. Instead of restarting or reloading nginx, (nothing to chance) I rebooted system. My setup is a base install of Debian Lenny, nginx dependencies, and apt-get install nginx; that's it. Very simple test server. I created a domain.com file in sites-available and did a symbolic link to sites-enabled. Here is my domain.com config file (done in accordance with best practice, and followed the pitfall documentation section of nginx):

server {
  server_name www.domain.com;
  rewrite ^ $scheme://domain.com$request_uri permanent;
}

server {
  server_name domain.com;
  location / {
  root /srv/www/sites/domain.com;
        }
        }

What am I missing here? I also tried with nginx-0.8.54; compiled the latest stable version. I tried on two different physical servers; tried on vmware VMs; and tried accessing from remote computer. The rewrite according to everyone's tutorial seems to work, but for me it doesn't. I put Apache servers together no prob, but I keep banging my head against the desk on nginx.

Also, I did a local test and edited C:\WINDOWS\system32\drivers\etc\hosts to point to domain.com and www.domain.com; still doesn't work.

Anyone have a suggestion? Or is this a big secret? Like some secret rewrite module enabler?

1
  • I also tried reversing from non www to wwww. Now both www.domain.com and domain.com don't work. domain.com FF spits out, "The page isn't redirecting properly. And www.domain.com FF spits out,"Server not found". Still clueless on how such a simple task can be so daunting.
    – user58261
    Dec 19, 2010 at 6:44

2 Answers 2

3

Your etc\hosts reads 4 wwww. Change it to 3 www and it will work. It sounds like maybe you need to get some rest. :)

1
  • Works, thanks ChrisJ. Yep I took two days off to see if the world still exist. Thanks everyone for your help. And I'm sorry, nginx for doubting you and thanks for the open source contribution. Nginx is definitely superior.
    – user58261
    Dec 21, 2010 at 2:46
0

www is a cname record, did you create this?

if you are running locally just add the www record to your hosts file, then you should be able to test if the redirect is working properly.. Actually, I do not think windows hosts file allows for this type of record. You may need to setup a DNS server.

4
  • TY, for reply. I am doing this locally, so it's not public. I use the C:\WINDOWS\system32\drivers\etc\hosts to point to the nginx server. Do you think that's the problem? If so I have plenty of parked domains I can run test on actual production servers.
    – user58261
    Dec 19, 2010 at 6:39
  • Also, my etc\hosts file reads: 192.168.200.156 wwww.domain.com domain.com. Could this be the problem; nginx doesn't redirect locally?
    – user58261
    Dec 19, 2010 at 6:47
  • Your right I don't have a local dns server. But, I have set up the same local scenarios with apache "thousands of times" using the host file with www and it redirects fine. But, with nginx it doesn't; what gives? Ok, to put it to the test I will do a live production test with CNAME and the whole enchilada. If it works then nginx should fix this in their next release, because this is BS.
    – user58261
    Dec 19, 2010 at 6:58
  • It's not nginx, I have this exact setup with /etc/hosts on my local dev machine and it works just fine. Setup the error log with debug level logging to see what's actually going on. Dec 19, 2010 at 8:30

You must log in to answer this question.