Nginx redirect one domain to another

domainnginxredirectredirectionslicehost

I have two domain's set up on my server. Domain 1 is configured with google apps so that mail.domain1.com goes to google's mail. However, I would like domain1.com to redirect to domain2.com.

Currently in my nginx.conf file

I had

server {
    listen 80;
    server_name domain2.com .domain1.com;
    rewrite ^/(.*) http://domain2.com permanent;
    root /home/demo/apps/cjl/public;
    passenger_enabled on;
    rails_spawn_method smart;
 }

When I did this Firefox popped up a "Redirect not configured correctly" error and said that it thought that the redirect would create a never ending loop.

I'm wondering how to set this up and any help would be appreciated. Thank you!

Best Answer

make another server {} for domain2.com.

The loop is happening due to the redirect being happening on both server_name's