Sensu - availability under nginx subpath

Hi, I have the following clause in my nginx config:

        location /sensu {
                rewrite                 ^/sensu(/.*) $1 break;
                proxy_pass              http://localhost:3000/;
                proxy_set_header        Host                    $host;
                proxy_set_header        X-Real-IP               $remote_addr;
                proxy_set_header        X-Forwarded-Host        $host;
                proxy_set_header        X-Forwarded-Server      $host;
                proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
                proxy_read_timeout      600s;
                proxy_http_version      1.1;
                proxy_set_header        Upgrade $http_upgrade;
                proxy_set_header        Connection "upgrade";
        }

I can’t seem to get Sensu dashboard working under the /sensu subpath in nginx. Has anyone else had this issue before? I cannot put Sensu dashboard in the main path.

Hi,

This is a known limitation with the dashboard currently.

The dashboard implementation is currently incompatible with subpath redirection like this due to the use of paths in the browser side javscript. For example, from looking at the nginx logs when I last attempted set this locally, i know there are some references to “/static/”, but there may be others. I believe you can confirm the paths by looking at the nginx logs.

I believe the possible workaround is to expose ‘/static’ as a location in your nginx config similar to your /sensu location such that /static is redirected to : http://localhost:3000/static/

But you’ll definitely want to confirm the details of what is needed from your nginx logs. This is implementation specific detail in how the dashboard works and not a documented API, so /static might not be the only path you’ll need to redirect.

I hope this helps.

Here my solution:

upstream backend {
    include /etc/nginx/upstream.conf;
}

server {
    listen       80;
    listen  [::]:80;
    autoindex off;
    gzip on;
    server_name  localhost;

    location /auth {
        proxy_pass http://backend/auth;
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;
    }
    location /graphql {
        proxy_pass http://backend/graphql;
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;
    }
    location /api {
        proxy_pass http://backend/api;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;
    }

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri /index.html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}
1 Like