Question

Deploying nuxt with pm2

I am trying to deploy a nuxtJs application together with pm2.

When I access the website, I get the classic nginx 502 bad gateway error message, and quiet honestly- Im clueless why.

Nginx configuration file:

server {
    index index.html;
    server_name subdomain.somedomain.com;

    location / {
        proxy_pass http://subdomain.somedomain.com:3001;
        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;
    }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/subdomain.somedomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/subdomain.somedomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = subdomain.somedomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

Output of my nginx errors:

2021/06/17 21:48:19 [error] 20202#20202: *134 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xxx.xxx, server: subdomain.somedomain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://164.90.164.216:3001/favicon.ico", host: "subdomain.somedomain.com", referrer: "https://subdomain.somedomain.com/"

Output of my pm2 list:

id  │ name           │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 5   │ subdomainApp    │ default     │ 2.15.3  │ cluster │ 20299    │ 14m    │ 0    │ online    │ 0.3%     │ 75.7mb   │ root     │ enabled  │
│ 6   │ subdomainApp    │ default     │ 2.15.3  │ cluster │ 20306    │ 14m    │ 0    │ online    │ 0.3%     │ 76.0mb   │ root     │ enabled

No errors when I try to reload nginx, build the nuxt app or other stuff like that. Im honestly out of options regarding debugging. Any suggestions please?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @soduno,

I would recommend checking if the service is actually listening on port 3001 by running the following netstat command:

netstat -plant | grep 3001

Feel free to share the output here.

Also I would recommend changing the following line from:

        proxy_pass http://subdomain.somedomain.com:3001;

To:

        proxy_pass http://127.0.0.1:3001;

That way the traffic would not be routed externally but would be proxied locally so if you have a firewall blocking the port it would not cause any issues.

Once you make the Nginx change make sure to run a config test with the following command:

sudo nginx -t

And if you get Syntax OK message, then restart Nginx:

sudo systemctl restart nginx

Let me know how it goes. Regards, Bobby