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;

    location / {
        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/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # 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 = {
        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:, server:, request: "GET /favicon.ico HTTP/1.1", upstream: "", host: "", referrer: ""

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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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:




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