Computersnyou

How to Rewrite domain in nginx [ quick tip ]

Posted on  1/10/2014

In nginx you can rewrite the incoming request for naked domain  ” example.com ” to  ” www.example.com ” just by using few lines . it’s so simple ,I will show you how to do that in proper way .

server {
  server_name example.com;
  return 301 $scheme://www.example.com$request_uri;
}
server {
  server_name www.example.com;
  * other config 
}

second way

server {

listen 80;
server_name example.com ;
return  http://www.example.com$request_uri;
}

server {
listen 80;
server_name www.example.com;
* other configuration options 
}

Download or embed this code on your blog  from http://paste.computersnyou.com/31 .

if you are having any kind of problem please post your question in comments or forum .

nginx wiki

common nginx pitfalls 


  • Home
  • About