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?
Best Answer
If you have reloaded your configuration (
nginx -s reload
) and nothing changed, then I would suspect somedefault_server
trick. Let's have a look at the documentation.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 your case, the "first server" is phpMyAdmin, since "p" comes before "s" (stats) in the alphabet. What happens is :
stats.mydomain.com
.server{}
block does not provide any location block matching your URI.From there :
Because of the following piece of configuration...
... the phpMyAdmin
server{}
is capable of handling any request, since it rewrites all the wrong ones asindex.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 :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).