Score:0

NGINX reverse proxy responds to IP but not domain name

vi flag

I have an nginx reverse proxy setup to point to my nodejs app. When I enter the server IP in the search bar, the website pulls up as expected. When I enter the domain name I get an ERR_CONNECTION_REFUSED error.

I have the following sites-available file for my site:

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

    server_name mywebsite.com www.mywebsite.com <server_ip>;

    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://0.0.0.0:3000/;
            #proxy_redirect http://127.0.0.1:3000/ https://$server_name/;
    }
}

I've also commented out everything in the default file to avoid conflict.

My ports should be open per ufw:

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
443                        ALLOW       Anywhere
22                         ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
22 (v6)                    ALLOW       Anywhere (v6)

When I do a ping on my domain name, it returns the correct IP address.

This is the output of netstat -tlnp

sudo netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      21671/PM2 v5.3.0: G
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      18646/sshd: /usr/sb
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26697/nginx: master
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      18657/systemd-resol
tcp6       0      0 :::22                   :::*                    LISTEN      18646/sshd: /usr/sb
tcp6       0      0 :::80                   :::*                    LISTEN      26697/nginx: master
dave_thompson_085 avatar
jp flag
What browser(s) on what platform(s)? Browsers don't need to, and fairly often don't, use the same name resolution as simpler programs like ping. Can you get a network trace with wireshark or tcpdump or similar to see _exactly_ what connection is being attempted and if it is correct? Or try curl -- that does 'plain' network connection (as long as you don't have a client-side/forward proxy set).
djdomi avatar
za flag
use 127.0.0.1 instead of 0.0.0.0 for the revese proxy, never seen such a config. Where is the Server hosted? how do you try to access?
Score:0
ws flag

When I enter the server IP in the search bar, the website pulls up as expected. When I enter the domain name I get an ERR_CONNECTION_REFUSED error.

Then the FIRST thing to check is what the domain name resolves as on the client. Try pinnging the domain name.

(It also proves that a lot of other things are not the cause, including the firewall)

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.