angularnginx

Angular Production Build -> no output / 502 Error with nginx


I have updated to the latest Angular version and now have a main.server.mjs file instead of main.js. I specified this in my pm2 ecosystem.config:

{
name : "angular_ssr",
instances: 1,
script : "/root/actions-runner/_work/dist/whoop/server/main.server.mjs",
autorestart: true
}

after a startOrRestart this instance is also shown as online. The nginx config has not changed:

server {
listen 80;
server_name whoop.com;
return 301 https://whoop.com/;
}

server {
listen 443 ssl;
server_name whoop.com;

ssl_certificate /etc/nginx/certs/whoop/bundle.crt;
ssl_trusted_certificate /etc/nginx/certs/whoop/intermediate_whoop.com.crt;
 ssl_certificate_key /etc/nginx/certs/whoop.com/whoop_com.key;
 include /etc/letsencrypt/options-ssl-nginx.conf;
 ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

 error_log /var/log/error.log;
 access_log /var/log/access.log;

 location /api { rewrite ^/api(.*)$ $1 break;
 proxy_pass http://localhost:3000/;
 proxy_http_version 1.1;
 } location / { proxy_pass http://localhost:4000/;
 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;
}

gzip on;
gzip_comp_level 5;
gzip_min_length 1100;
gzip_buffers 4 32k;

gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/xml;
#gzip_disable "MSIE [1-6].";
}

Unfortunately, I only get a "502 Bad Gateway" when I try to open the page.

What could be the reason for this - how can I debug the app as it is not logging ANY errors (not in pm2 logs and not in nginx) When I run a node main.server.mjs I don't get any error messages.


Solution

  • It seems that the problem is caused by pm2 not being able to run the new server.ts configuration of 'angular 19'. I hope there will be a solution in the next pm2 release.

    https://github.com/Unitech/pm2/issues/5921

    https://stackoverflow.com/a/79222463/9576431