1

I used the CNAME wild card DNS entry like:

@    IN A      ip.add.re.ss  
www  IN CNAME  @  
*    IN CNAME  @  

My root domain.com and sub1.domain.com are accessible (on the same digitalocean droplet).
But if I try to access sub2.domain.com, after web server configuration, it takes me to sub1.domain.com.
I'm using NginX server blocks and all domains are using the same IP address. (I've configured domain.com on 80 while I access/configure subs like sub1.domain.com:8088 and sub2.domain.com:8088)

sub1 is phpmyadmin:

server {
    listen          8088;
    server_name     phpmyadmin.mydomain.com;
    root            /usr/share/nginx/html/phpmyadmin;
    index           index.php index.html index.htm;
    access_log      /var/log/nginx/phpmyadmin/access.log;
    error_log       /var/log/nginx/phpmyadmin/error.log;
 
    if (!-e $request_filename) {
        rewrite ^/(.+)$ /index.php?url=$1 last;
        break;
    }
 
    # Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        access_log        off;
        expires           360d;
    }
 
    location ~ /\.ht {
        deny  all;
    }
 
    location ~ /(libraries|setup/frames|setup/libs) {
        deny all;
        return 404;
    }
 
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

sub2 is stats:

server {
    listen          8088;
    server_name     stats.mydomain.com;
    root            /usr/share/nginx/html/piwik;
    index           index.php piwik.php;
    access_log      /var/log/nginx/piwik/access.log;
    error_log       /var/log/nginx/piwik/error.log;
 
    location ~ /\.ht {
        deny  all;
    }
 
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

My /etc/hosts:

127.0.0.1   localhost mydomain
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters  

Hitting in the browser phpmyadmin.mydomain.com:8088 works fine but hitting stats.mydomain.com:8088 takes me to phpmyadmin login page. Do I need to create more A or CNAME records for more than one subdomains?

1

1 Answer 1

3

If you have reloaded your configuration (nginx -s reload) and nothing changed, then I would suspect some default_server trick. Let's have a look at the documentation.

nginx tests only the request’s header field “Host” to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port.

Basically, this means that if no server{} provides a handle for your request, it'll be transferred to the default server. Since you haven't explicitely set one...

In the configuration above [see example in the documentation], the default server is the first one — which is nginx’s standard default behaviour.

In your case, the "first server" is phpMyAdmin, since "p" comes before "s" (stats) in the alphabet. What happens is :

  • Your request is made to stats.mydomain.com.
  • The stats server{} block does not provide any location block matching your URI.
  • nginx forwards the request to the default server, i.e. phpMyAdmin

From there :

  • phpMyAdmin can handle the request, or...
  • it cannot, resulting in a 404 or 403 error.

Because of the following piece of configuration...

if (!-e $request_filename) {}

... the phpMyAdmin server{} is capable of handling any request, since it rewrites all the wrong ones as index.php requests. You are redirected to the login page because this is the default phpMyAdmin page when it can't handle the $_GET['url'] parameter.

To confirm the theory, just add default_server to the listening port in your stats configuration :

listen 8088 default_server;

If the behaviour changes, then you'll be sure about it. The next step is all about investigating the logs. It is possible that your stats configuration does not match your actual directory structure, causing a 404 or 403 error (which first resulted in the request being forwarded to phpMyAdmin, the default server).

1
  • Thanks John for the heads up. The default_server trick was still taking me to phpmyadmin site. However, I found in the error log that it couldn't find the directory /var/log/nginx/piwik/ After creating that directory, it's working fine.
    – Shah-G
    Jul 1, 2014 at 11:17

You must log in to answer this question.

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