1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular SSR on Plesk 502 Bad Gateway error

Discussão em 'Angular' iniciado por Iñigo Gorosabel, Maio 15, 2025.

  1. I am setting up an Angular app that uses SSR on a Linux Debian 11.11 server with Plesk Obsidian 18.0.69. I have installed NodeJS Toolkit and I have enabled Node on a subdomain where the app will go.

    The Angular app is using Angular 19.2.10, and the Node configuration is this:

    Node.js version: 22.15.0
    Package administrator: npm
    Document root: /dev.domain.com/public/dist/browser
    Application mode: development
    Application URL: http://dev.domain.com
    Application root: /dev.domain.com/public/dist abierto
    Application start file: server/server.mjs
    Custom environment variables: - PORT: 4000


    The problem is that I get a 502 Bad Gateway error when I open the app on a browser. Check the log I saw this:

    2265912#0: *189198 connect() failed (111: Connection refused) while connecting to upstream


    Looks like nginx cannot get to the Node app. On the nginx configuration I have this configuration:

    Proxy mode - unchecked
    Smart processing of static files - checked
    Serve static files directly with nginx - unchecked
    Activate nginx cache copy - unchecked
    Aditional nginx directives:

    location / {
    proxy_pass http://127.0.0.1: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;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|webp)$ {
    root /var/www/vhosts/domain.com/dev.domain.com/public/dist/browser;
    expires 1y;
    access_log off;
    add_header Cache-Control "public";
    }


    I opened a ssh to the server and I tried starting the Angular SSR application directly with:

    node public/dist/server/server.mjs


    And everything started working. Using this command:

    ss -tuln | grep 4000


    I saw the node application running, but when I stop it using Control + C the application didn't show up anymore. If I click on "Restart app" on the Node section of the subdomain, a message appears saying "the application will restart after the first request", but I still get a 502 and using the "ss" command doesn't show anything working on port 4000.

    The Angular SSR app on the server.mjs basically starts an Express server, so any help on setting this up? I have been looking everywhere but the Node documentation for Plesk is almost nothing.

    Thanks!

    Continue reading...

Compartilhe esta Página