Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Jul 19, 2012 9:49 am 
Offline
Newbie

Joined: Thu Jul 19, 2012 8:10 am
Posts: 2
We have Linode node-balancer which splits requests between 2 nginx servers.

The identical Nginx servers have been configured to serve for their IP Addresses (local) not to the domain name (mysite.com).
How I can setup a 301 redirect in those servers so that http://mysite.com/* is redirected to http://www.mysite.com

I have done similar configs for sites which did not use Node balancers, so I find this situation tricky.

Thanks in advance for your help.


Top
   
PostPosted: Fri Jul 20, 2012 1:02 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
Two approaches:

1) The wrong but easy way:

Code:
server {
  listen ...
  server_name example.com www.example.com ...;


  # Redirect www.example.com to example.com
  if ($host ~* (www)\.(.*)) {
    set $host_without_www $2;
    rewrite ^(.*)$ $scheme://$host_without_www$1 permanent;
  }


2) The more correct way:

Code:
server {
  listen ...
  server_name example.com ...;
  # All the existing configuration, but without www.example.com in the server_name
}

server {
  listen ...
  server_name www.example.com;

  location / {
    rewrite ^/(.*) $scheme://example.com/$1 permanent;
  }
}


The node balancer does not make a difference here.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
PostPosted: Fri Jul 20, 2012 2:02 pm 
Offline
Newbie

Joined: Thu Jul 19, 2012 8:10 am
Posts: 2
@hoopycat Thanks for your reply.

Can you please clarify one thing. How does the nodebalancer request the web servers? Via the IP with the domain name, or just the IP.
In other words, will the web servers answer to the domain name or to the IP?


Top
   
PostPosted: Fri Jul 20, 2012 2:06 pm 
Offline
Linode Staff
User avatar

Joined: Tue Apr 15, 2003 6:24 pm
Posts: 3090
Website: http://www.linode.com/
Location: Galloway, NJ
The Host header is not modified, so your webserver will know which virtualhost to serve from.

-Chris


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group