Incorrect redirect after (un)monitoring a service in HTTP interface

Issue #1077 resolved
Dominik Leiner created an issue

I use the same nginx configuration on several Ubuntu servers to proxy monit and make the HTTP interface available via SSL to the outside world (https://example.com/monit/).

On a few servers, I encounter this problem: After selecting a service from the overview (going to https://example.com/monit/xyz), I see the details and the buttons [Start service] … [Disable monitoring]. When I click the [Disable monitoring] (or any other) button, the POST goes through and the action is performed, but the HTTP answer includes a redirect to the wrong address:

Location: /xyz

The leading slash is incorrect, so my browser trys to open https://example.com/xyz instead of https://example.com/monit/xyz.

Comments (5)

  1. Dominik Leiner reporter

    This is non-representative, but it seems the issue occurs systematically on Ubuntu 22.04, not with Ubuntu 20.04 (each with the monit version delivered by the distribution).

  2. Henning Bopp

    Could you check (or test), if this problem persists, if you have proxy_redirect enabled? Usually nginx is kinda good on rewriting those redirects. See documention for details.

    The default (where the value also is default) should work, but it's only adding one single line and do a reload ;))

    If setting it to default does not work, try proxy_redirect http://localhost:8212 https://example.com/monit/ or proxy_redirect / https://example.com/monit/.

  3. Dominik Leiner reporter

    Of course, I had configured nginx according to the manual (https://mmonit.com/wiki/Monit/Nginx) Here is an example from one of the servers:

        location ^~ /monit/ {
                rewrite ^/monit/(.*) /$1 break;
                proxy_ignore_client_abort on;
                proxy_pass   <http://127.0.0.1:2812;>
                proxy_redirect  <http://127.0.0.1:2812> /monit;
                proxy_cookie_path / /monit/;
        }
    

    However, thanks to your answer, I tried the full URL in the proxy_redirect line, looking like this …

    proxy_redirect <http://127.0.0.1:2812> https://my.server.example.com/monit;

    And one nginx reload later … the problem disappeared.

    Would you mind, updating the manual? It ran into this issue on no less than 3 servers with the latest Ubuntu before I ended up here :)

  4. Log in to comment