sk89q / warmroast

Java application CPU sampler w/ web-based UI
230 stars 37 forks source link

Paths are broken when proxied through nginx #13

Open john01dav opened 7 years ago

john01dav commented 7 years ago

A server admin may want to proxy warmroast through nginx (or another web server) for several reasons such as authentication behind a username and password and TLS. When I attempted to do this via nginx, it worked correctly except that the paths given by warmroast are not relative. Specifically, the link to /stack and the styleheets do not take into account warmroast's new url. It should be noted that I am trying to run at a url like example.com/warmroast using the following nginx configuration:

        listen 80;
        listen [::]:80;
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        root /usr/share/nginx/html/admin;

        index index.html index.htm;

        server_name <redacted>;

        include /etc/nginx/snippets/ssl.conf;

        location / {
                try_files $uri $uri/ =404;
        }

        location /warmroast {
                proxy_pass http://127.0.0.1:23000/;
                proxy_set_header Host $host;
        }
}

Perhaps a command line flag such as --relative-paths or --warmroast-http-root would be the best solution?

DosAmp commented 7 years ago

As a workaround, you can use the nginx sub module to replace absolute URLs in WarmRoast's HTML output with relative ones. As an example, we're not using custom CSS, so we only have to rewrite the /stack resources:

location /warmroast/ {
    proxy_pass http://localhost:8888/;
    proxy_http_version 1.1;
    proxy_set_header Accept-Encoding '';
    sub_filter '/stack' 'stack';
    error_page 502 /warmroast_offline.html;
}