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.

I need to forward all visitors from "domain.com" to "www.domain.com".

I know this has something to do with altering the nginx config file but am not sure what to do or what code to use.

I am using nginx as the server.

Any help would be appreciated :)

share|improve this question
    
1  
Just do opposite: serverfault.com/questions/35955/… –  quanta Aug 2 '11 at 14:15

3 Answers 3

up vote 1 down vote accepted

In my own NGINX setup, I made a separate vhost for domain.com:

server {
  listen   1.2.3.4:80;
  server_name  domain.com;
  rewrite  ^(.*) http://www.domain.com$1 permanent;
}
share|improve this answer
    
Thanks Sgaduuw your solution have helped and it works :) –  Jayesh Gopalan Aug 4 '11 at 7:41

Apparently I can't just have a link as an answer...

Anyway, check out this question: Nginx: Forward all Subdomains

The config there should work for you.

share|improve this answer

You can rewrite the URL in the config file like this:

server {
    server_name  domain.com;
    rewrite ^(.*) http://www.domain.com$1 permanent;
}

server {
    server_name  www.domain.com;
    #My other config options
}
share|improve this answer
    
Thanks TiZon for your solution and it works and it helped me once again Thanks :) –  Jayesh Gopalan Aug 4 '11 at 7:42
    
@Jayesh Gopalan Could you mark the question as solved then? That wey it won't pop up on the main page as an unsolved question. –  Bart De Vos Aug 4 '11 at 8:01

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.