Index for subdomain (api.domain.com) not working, serves pages for domain.com


#1

I have 2 sites as below:

# cat /etc/nginx/sites-available/example.com
server {
    listen 443;
    ssl on;
    server_name www.example.com;

    ssl_certificate /var/www/example.com/cert/example.com.crt;
    ssl_certificate_key /var/www/example.com/cert/example.com.key;

    access_log /var/log/nginx/example.com.access.log rt_cache;
    error_log /var/log/nginx/example.com.error.log;

    root /var/www/example.com/htdocs;
    index index.php index.html index.htm;

    include common/wpfc.conf;
    include common/wpcommon.conf;
    include common/locations.conf;
    include /var/www/example.com/conf/nginx/*.conf;
}

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

Please note the redirect above for http (both with and without www) to https://www.example.com and I think this is what may be interfering.

# cat /etc/nginx/sites-available/api.example.com
server {
    listen 80;
    server_name api.example.com;

    access_log /var/log/nginx/api.example.com.access.log rt_cache;
    error_log /var/log/nginx/api.example.com.error.log;

    root /var/www/api.example.com/htdocs;
    index index.html index.php index.htm;

    include common/php.conf;
    include common/locations.conf;
    include /var/www/api.example.com/conf/nginx/*.conf;
}

The following works with the correct file served: http://api.example.com/test.php

However, despite there existing /var/www/api.example.com/htdocs/index.html (and also index.php) when I navigate to http://api.example.com it just loads up content for https://www.example.com and I don’t know why (this only happens for index files).

Any ideas what i am doing wrong and how to resolve please? Many thanks


#2