Ansible playbook: The server connection failed with the error “Bad Gateway”

i installed multi-node mass on one server (high available mode) with two regiond VM and two rackd VM for test multinode.
I turned it off all regiond and all rackd vms and turned it on again and now when I open maas dashboard show this error: The server connection failed with the error “Bad Gateway”

how can I fix it?

region1:~$ sudo maas status
bind9 RUNNING pid 1330, uptime 0:05:12
http RUNNING pid 1331, uptime 0:05:12
ntp RUNNING pid 1332, uptime 0:05:12
proxy STOPPED Not started
regiond RUNNING pid 1333, uptime 0:05:12
syslog STOPPED Not started

Hi @mehdijalalii,

Could you please specify which version are you using and which installation type you used (deb or snap)? Is it a transient error or is the message on the UI persistent?

Hi @r00ta
I installed mass with the official ansible playbook.
these are related variables:

maas_version=“3.3”
maas_installation_type=“snap”
maas_snap_channel=“stable”

Is the message persistent or transient?

The message in the maas dashboard is persistent and that’s why I don’t have access to the dashboard and I only see this message.

Could you upload a screenshot? Btw the syslog service is not enabled by default. If you enabled this then it’s wrong.

But I suspect your configuration issue stands somewhere else. Even if 502 should be returned by nginx, could you check the logs https://maas.io/docs/about-log-files#heading--Using-the-logs-directly and see if is there anything useful there?

If you navigate to myserverip:5241/MAAS/api/2.0/describe/ do you get a response or do you get 502?

thank you for trying to solve my problem. I get 502 when I run this url

Did you setup haproxy?

yes. but when I want to test that, I use 5241 and 5242 ports for direct test that without load balancing To simplify it. I used NAT because I have only one public IP

content of /var/snap/maas/current/http/regiond.nginx.conf?

$ cat /var/snap/maas/current/http/regiond.nginx.conf
    # -*- mode: nginx -*-

    upstream regiond-webapp {
        server unix:/var/snap/maas/28521/maas-regiond-webapp.sock;
    }

    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_read_timeout 900s; # to match the Twisted one
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $http_host;

    server {
        listen [::]:5240;
        listen 5240;

        absolute_redirect off;

        location = / {
            return 301 /MAAS/r/;
        }

        location ~ ^/MAAS/?$ {
            return 301 /MAAS/r/;
        }

        location /MAAS {
            proxy_pass http://regiond-webapp;
        }

        location /MAAS/ws {
            proxy_pass http://regiond-webapp;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Upgrade $http_upgrade;
        }

        # static assets

        location ~ ^/MAAS/machine-resources/(.*)$ {
            root /snap/maas/28521/usr/share/maas/machine-resources;
            try_files /$1 =404;
        }

        location = /MAAS/docs {
            return 301 /MAAS/docs/;
        }

        location ~ ^/MAAS/docs/(.*)$ {
            root /snap/maas/28521/usr/share/maas/web/static/docs;
            # redirect to the UI version if the page is not found by default
            try_files /$1 /$1.html /ui/$1 ui/$1.html /$1/index.html =404;
        }

        location ~ ^/MAAS/assets/(.*)$ {
            root /snap/maas/28521/usr/share/maas/web/static/assets;
            try_files /$1 =404;
        }

        location ~ ^/MAAS/r/(.*)$ {
            root /snap/maas/28521/usr/share/maas/web/static;
            try_files /$1 /index.html =404;
        }

        location /favicon.ico {
            root /snap/maas/28521/usr/share/maas/web/static;
            try_files /maas-favicon-32px.png =404;
        }
    }

I guess I’m missing a bit your setup then. As you can see from the region nginx configuration, nginx is listening to 5240. Can you try to access <regionip>:5240?

in NAT I was forwarding serverpublicip:5241 to region VM internal IP: 172.16.1.15: 5240 and I changed 5241 to 5240 but it did not differ from before.
additionally I tested curl http://172.16.1.15:5240/MAAS/api/2.0/describe/ from region VM terminal and get 502

from the vm terminal, can you try with curl localhost:5240/MAAS/api/2.0/describe/ please?

1 Like

returned 502 when i tested it

curl --unix-socket /var/snap/maas/current/maas-regiond-webapp.sock http://localhost/MAAS/api/2.0/describe/ ?

result:

root@region1:/home/mehdi# curl --unix-socket /var/snap/maas/current/maas-regiond-webapp.sock http://localhost/MAAS/api/2.0/describe/
curl: (7) Couldn’t connect to server

root@region1:/home/mehdi# curl --unix-socket /var/snap/maas/current/maas-regiond-webapp.sock http://localhost:5240/MAAS/api/2.0/describe/
curl: (7) Couldn’t connect to server

I checked /var/snap/maas/current/maas-regiond-webapp.sock is exist and this is ok.

would it be a problem for you to try to upgrade to 3.3/beta? Then you should have multiple unix sockets under /var/snap/maas/current/. Could you then try again with the command above (with for example maas-regiond-webapp.sock.0?)