Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Rewriting www to non-www is not working.

The URL works but 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 file in sites-available and did a symbolic link to sites-enabled. Here is my config file (done in accordance with best practice, and followed the pitfall documentation section of nginx):

server {
  rewrite ^ $scheme://$request_uri permanent;

server {
  location / {
  root /srv/www/sites/;

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 and; still doesn't work.

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

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

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. :)

share|improve this answer
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 '10 at 2:46

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.

share|improve this answer
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 '10 at 6:39
Also, my etc\hosts file reads: Could this be the problem; nginx doesn't redirect locally? – user58261 Dec 19 '10 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 '10 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. – Martin Fjordvald Dec 19 '10 at 8:30

Your Answer


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