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've about 4 different hostnames defined in the sites-enabled/domain.tld files. Each of the files are in the following fashion:

#Redirect everything to the main site.
server {
        server_name *.abc.net;
        listen 80;

        root /var/www/vhosts/abc.net/httpdocs;

        if ($http_host != "acb.net") {
                rewrite ^ http://abc.net$request_uri permanent;
        }

        include /etc/nginx/conf.d/restrictions.conf;

        #Additional rules go here.

        # Only include one of the files below.
        include /etc/nginx/conf.d/wordpress.conf;

        # W3 Total Cache Rules
        include  /var/www/vhosts/abc.net/httpdocs/nginx.conf;
}

Each of the server blocks in the site-enabled folder only change the domain name, so abc.net becomes xyz.com and so on.

The problem is that, regardless of all these configuration files in place, all the vhosts just redirect to one vhost. I've tried restarting the nginx server, reloading it, and also rebooted the server.

These requests are sent to an upstream php, running PHP-FPM, if that helps, and all the domains are running wordpress on them.

Appreciate your help. Thank you :)

share|improve this question
    
please add the result for curl -I test.abc.net and curl -I test.xyz.net –  Marcelo Bittencourt Dec 30 '11 at 6:33
    
Doing curl -I mpjtime.com gives me: HTTP/1.1 301 Moved Permanently Server: nginx/1.0.10 Date: Fri, 30 Dec 2011 08:36:22 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://mariouana.com/ And for another domain on the same nginx server: curl -I geekd.in HTTP/1.1 301 Moved Permanently Server: nginx/1.0.10 Date: Fri, 30 Dec 2011 08:36:31 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: http://mariouana.com/ –  Karthik Kastury Dec 30 '11 at 8:39
add comment

2 Answers

up vote 1 down vote accepted

Try change the server_name block in each vhost

server {
  ...
  server_name   example.com  *.example.com;
  ...
}

or, as recommended by nginx

server {
    listen       80;
    server_name  *.example.com;
    return       301 http://example.com$request_uri;
}

server {
    listen       80;
    server_name  example.com;
    ...
    your config removing the if part
    ...
}
share|improve this answer
    
This works great. Thank you. :) –  Karthik Kastury Jan 1 '12 at 1:14
add comment

so...

        if ($http_host != "acb.net") {
            rewrite ^ http://abc.net$request_uri permanent;
        }

is included in each vhost block? Or did you remember to change the hostname to the proper value here as well?

If not, that would explain a lot :-)

share|improve this answer
    
I've replaced the value, correspondingly for each of the server vhost {} blocks. –  Karthik Kastury Dec 30 '11 at 8:34
add comment

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.