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 am trying to setup Nginx to redirect different domains to a single one - http://knyt.tl:

server {
  listen 81;
  server_name _;
  return 302 http://knyt.tl/;
  rewrite ^ http://knyt.tl permanent;
}

server {
    listen 81;
    server_name knyt.tl;        
}

However nginx just returns contents of the domain knyt.tl and the different domains are not redirected with neither return 302, nor rewrite ^.

I've also tried following:

server {
    listen 81;

    if ($host != 'knyt.tl') {
        rewrite ^ http://knyt.tl/ permanent;
    }
 }

But the clause seems to be completely ignored as well.

Only time I managed to get it running was when redirecting from www.knyt.tl to knyt.tl.

share|improve this question
1  
You're listening on port 81. Are you using something else to actually answer requests on port 80? That's where you need to look for the problem. –  Michael Hampton Jan 23 '13 at 22:30
    
Yes, I am running apache on 80 and I don't want them to interfere. –  Vojtěch Jan 23 '13 at 22:33
    
Then you also need to look at (and post here) your Apache configuration. –  Michael Hampton Jan 23 '13 at 22:34
    
But I don't see a reason why they should interact - I suppose if I tell nginx to use port 81, why should he care about port 80? –  Vojtěch Jan 23 '13 at 22:40
    
Because all of your requests come in on port 80, so Apache is touching them all. –  Michael Hampton Jan 23 '13 at 22:43

1 Answer 1

up vote 1 down vote accepted

You have nginx listening on port 81. But you have Apache actually answering requests on port 80. That's where you need to look for the problem, since all of your incoming requests come in on port 80.

share|improve this answer

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.