Home > Software design >  Nginx does not listen to port 3000
Nginx does not listen to port 3000

Time:11-28

I have a Nuxt app and I try to config Nginx , when I use curl localhost:3000 I can see my website tag and status 200 , but I can not open my website with domain name , it's take to load for like 2 minutes and then it will show me " This site can’t be reached " I made an error log and this was in error log

[error] 72792#72792: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.68.50.201, server: domain.com , request: "GET / HTTP/1.1", upstream: "http://[::1]:3000/", host: "domain.com"

I try this command netstat -tulpn to make sure nginx is listening . and here is the result

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      70267/node
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      72791/nginx: master
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN      773/mysqld
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      773/mysqld
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      72791/nginx: master
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      61184/systemd-resol
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      689/sshd: /usr/sbin
tcp6       0      0 :::443                  :::*                    LISTEN      72791/nginx: master
tcp6       0      0 :::80                   :::*                    LISTEN      72791/nginx: master
tcp6       0      0 :::22                   :::*                    LISTEN      689/sshd: /usr/sbin
udp        0      0 127.0.0.53:53           0.0.0.0:*                           61184/systemd-resol

this is my nginx config

server {
        listen 443 ssl ;
        listen [::]:443 ssl ;
        include snippets/self-signed.conf;
        include snippets/ssl-params.conf;
        server_name domain.com www.domain.com;

        root /path/to/my/front-app;

        error_log /var/log/nginx/nuxt.error.log;


        index index.html index.htm;

        location / {
        proxy_pass http://localhost:3000;
        include /etc/nginx/proxy_params;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        }
}
        server {
                 listen 80;
                 listen [::]:80;
                  server_name myServerIp;
                 return 301 $https://myServerDomain;
                }

CodePudding user response:

I will write an answer here mainly because I will feel too limited in a comment regarding layout/presentation. Please don't take it as a definite answer per se.
(also, OP reached out directly to me hence my effort here)

First, I would start by migrating to the latest version of Nuxt (v3.0 stable) rather than an RC. So that way, you're on the latest and greatest.
Then, I'll double-check that I'm using Node v18 because this is the LTS and you should use the LTS.
I'll start debugging the app locally, hence yarn build && yarn preview. If that works well, then the issue is probably not coming from Nuxt.
(I also recommend yarn or PNPM as package managers rather than npm because of speed error explicitness when installing any NPM packages)


You can then try to host your app on a Node.js-powered PASS like Render.com or Heroku. That way, you leave the configuration of the VPS to somebody else to manage and focus primarily on your app. Follow the official guides available here.
If that works, then it's definitely not a Nuxt issue.

I'm a bit rusty on the Nginx part, so I'm not sure to help quickly with that part as I used to.
My main question here is, "Do you really need to manage your own server?"
If not, then you could focus on the code itself and let the deployment part aside, especially if is taking 2 weeks of your time and not bringing a lot of value.

If it is something that you truly care about, then the first step would be to double-check some of those points:

  • try to expose a simple .html file to your domain name, access it from www.yourcoolwebsite.com
  • try to expose a Node.js app, and render a view to double-check the Node.js part
  • if the 2 above work well, your Nuxt app should be working totally fine too!

Here you're trying to achieve too many things at the same time, you need to proceed by elimination and debug with what you know/are not sure of.
Fixing an issue with various variables without isolation is too time-consuming and not efficient.

  • Related