'How do I access Nginx server block externally to get rid of "Error 404 Not Found"?

I have Nginx installed on my Ubuntu 20.04 LTS virtual machine (VM). I have put the same HTML file in default and another virtual server block (my_domain). I can access the HTML file locally in a browser via locahost/my_file.html and http://my_domain/my_file.html.

Now, I want to access the HTML file in my_domain from another machine (outside VM). To do so, I have added the VM's public IP to etc/hosts with server_name. I am trying to access the HTML file from another machine like this:

http://my_ip/my_domain/my_file.html

and getting the Error 404 not found error.

What is it that I am doing wrong, and how can I fix this?

I can externally access the default server block via http://my_ip/my_file.html but not the my_domain block.

Here is how the configuration files look like. Anything wrong here?

my_domain

server {
        listen 80;

        root /var/www/my_domain/html;
        index my_file.html;

        server_name my_domain my_domain.com;

        location / {
                try_files $uri $uri/ =404;
                autoindex on;
                autoindex_exact_size off;
        }
}

default

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index my_file.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source