subdomains

I’m sure it’s something dumb I’m missing. I’m just bumbling around with this, decided to learn something new

I went ahead and removed all the DNS record stuff from DigitalOcean and set it all up with NameCheap. This is what I have for records there:

c96970d67c8131542afa7c32d3c62c9b50f5c9e5

Does that look correct?

If so, I have my website files set up on my VPS like this:

/var/www/domain.com/index.html

and

/var/www/forum.domain.com/index.html

Is this correct?

If so, then I have the two nginx config files in

/etc/nginx/sites-available/

top domain is:

server {
        listen 80 default_server;
        root /var/www/domain.com;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name domain.com;

        location / {
                try_files $uri $uri/ =404;
        }

	location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

	location ~ /\.ht {
                deny all;
        }
}

And subdomain is:

server {
        listen 80;
        root /var/www/forum.domain.com;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name forum.domain.com;

        location / {
                try_files $uri $uri/ =404;
        }

	location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

	location ~ /\.ht {
                deny all;
        }
}

Both of these are linked to

/etc/nginx/sites-enabled/

I’ve removed the actual domain name for now.

I’m not sure what I’m doing wrong. When I go to the subdomain the index file for the main domain is displayed.

I host 2 domains on the same server, added a subdomain to one of them, works okay…

image

    server {
        server_name  cabin.digital www.cabin.digital;
        root         /usr/share/nginx/cabin.digital;

        index index.html;

        listen       80;
        listen       [::]:80;

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
   }

    server {
        server_name  wood.cabin.digital;
        root         /usr/share/nginx/cabin.digital/wood;

        index index.html;

        listen       80;
        listen       [::]:80;

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
   }

the other domain has TLS so I don’t wanna share it’s the same, but it has the default_server on listen

did you run nginx -t? did you reload the service? you probably did, but gotta ask :stuck_out_tongue:

Yeah, I restarted the service after changes.

Your root path structures are different. Maybe that’s it?

it’s just where I put the files, just make sure nginx user has the perms to access those

did you put any files for the subdomian?

might be wrong, but if you didn’t it won’t 404 at first, it will go to the default_server and try there. so if you don’t have your index for subdomain, it will go grab the other one.

I think, not sure

@BirdoBaggins can confirm?

Yeah, there’s an index.html file in the subdomain directory

It should 404

Your link might be broken. Double check it

[admin@rohan ~]$ cd /etc/nginx/sites-available/
[admin@rohan sites-available]$ ls
forum.marasm.xyz  marasm.xyz
[admin@rohan sites-available]$ sudo ln -s /etc/nginx/sites-available/forum.marasm.xyz /etc/nginx/sites-enabled/forum.marasm.xyz
[sudo] password for admin: 
ln: failed to create symbolic link '/etc/nginx/sites-enabled/forum.marasm.xyz': File exists
[admin@rohan sites-available]$ sudo ln -s /etc/nginx/sites-available/marasm.xyz /etc/nginx/sites-enabled/marasm.xyz
ln: failed to create symbolic link '/etc/nginx/sites-enabled/marasm.xyz': File exists
[admin@rohan sites-available]$ 

Checked and both copies match and updates when the file in available is changed.

just to make sure we’re not missing the completely blatantly obvious and as a sanity check… your index.html is actually different for each right?

2 Likes

The contents are different, yes.