Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to setup Nginx to redirect different domains to a single one -

server {
  listen 81;
  server_name _;
  return 302;
  rewrite ^ permanent;

server {
    listen 81;

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

I've also tried following:

server {
    listen 81;

    if ($host != '') {
        rewrite ^ permanent;

But the clause seems to be completely ignored as well.

Only time I managed to get it running was when redirecting from to

share|improve this question
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
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


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.