1

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 :)

2
  • please add the result for curl -I test.abc.net and curl -I test.xyz.net Dec 30, 2011 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/ Dec 30, 2011 at 8:39

2 Answers 2

2

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
    ...
}
0
0

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 :-)

1
  • I've replaced the value, correspondingly for each of the server vhost {} blocks. Dec 30, 2011 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .