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:

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…

    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.

I did it.

I nuked the VPS and started over. This time I am using Ubuntu and Apache2.

Now www.marasm.xyz works, and forum.marasm.xyz works.

I am not too sure what I did to make it work beyond using Apache instead of Nginx and following some guides.

1 Like

Just what are you trying to pull here, guy?

:wink: Jk. Good job. I remember when I got my first Apache/Nginx config working.

Naw, I’m not making a forum. Well, not a public one, anyway. Maybe private for my siblings and myself. Dunno.

Just out out curiosity, does it matter if the .xyz is in the folder/file names? Like /var/www/marasm.xyz and marasm.xyz.conf? This time around I didn’t do that.

1 Like

It doesn’t. My Nginx has been extra.conf and default.conf plenty of times.

It helps with managing it, though. So if you have HAProxy or Nginx with 10 or 20 sites, naming them admindev.tech.conf and marasm.xzy.conf helps organizing.

Yeah, I’m not planning on more than one site. The guide I followed had me put the site conf in sites-available, then run a command to enable them. I so far have two confs for the main site and subdomain. Seems to work.

Next up is https, then basic main site and a forum or rocketchat. I also wanted to do a nextcloud and point a subdomain to that, but now I am behind CGNAT so that might be difficult.