Score:0

Nginx: can reach a site via IP address but it doesn’t work with the domain name

lu flag

I’ve started a nginx webserver recently with Ubuntu Server 22.04 as usual. The hypervisor is VMware Workstation 16.2.4. When I open the site http://192.168.0.213 I can see the default nginx page. But if I try to use my domain name example.com page won’t be found… I make attempts on my host and on other virtual machines using curl. The result is the same. And I’m not able to open my site even from webserver! The command nginx -t output is successful.

obfuscateduser@dnsserver:~$ curl http://example.com
curl: (7) Failed to connect to example.com port 80 after 0 ms: Connection refused

obfuscateduser@webserver:~$ curl http://example.com
curl: (7) Failed to connect to example.com port 80 after 1 ms: Connection refused

/etc/nginx/sites-available/example.com

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

        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;

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

/var/www/example.com/html/index.html

<html>
    <head>
        <title>Welcome to EXAMPLE.COM!</title>
    </head>
    <body>
        <h1>Success!  The your_domain server block is working!</h1>
    </body>
</html>

Permissions

obfuscateduser@webserver:~$ ll /var/www/example.com/html/
total 12
drwxr-xr-x 2 obfuscateduser obfuscateduser 4096 Jan 12 12:00 ./
drwxr-xr-x 3 root root 4096 Jan 11 17:19 ../
-rw-rw-r-- 1 obfuscateduser obfuscateduser  172 Jan 12 11:39 index.html

Firewall output

Status: active

To                      Action      From
--                      ------      ----
Nginx HTTP              ALLOW       Anywhere                 
OpenSSH                 ALLOW       Anywhere                 
Nginx HTTP (v6)         ALLOW       Anywhere (v6)            
OpenSSH (v6)            ALLOW       Anywhere (v6)       

Should I shut down the firewall? Or should I add a special entry in DNS zones files? Might I add some other records to the example.com file?

diya avatar
la flag
Is the DNS record for `example.com` actually pointing to the correct IP-address 192.168.0.213 ?
Ilya Shmadchenko avatar
lu flag
No, there's only an entry `webserver IN A 192.168.0.213` in the forward zone file. And `213 IN PTR webserver.example.com.` for the reverse zone.
diya avatar
la flag
Consider running curl with increased verbosity i.e. `curl -v curl http://example.com` and for additional understanding and debugging https://serverfault.com/q/725262/984089 and https://serverfault.com/a/1109720/984089
vidarlo avatar
ar flag
@IlyaShmadchenko So you don't have a A record from `example.com` pointing to your webserver? If so, that's obviously why it doesn't work.
Ilya Shmadchenko avatar
lu flag
@diya, @vidarlo, I've added `example.com. IN A 192.168.0.213` to the `forward` zone. Now `curl` is working fine, I can see my site. Thank you! Should I add the same record to the `reverse` zone? Anyway, I'm going to check the `webserver`'s status tomorrow.
sv flag
No need to use reverse zone to access the site!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.