Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Funny resource URL prefix disallows using locust behind nginx proxy #2030

Closed
mrdeveloperdude opened this issue Feb 25, 2022 · 7 comments
Closed

Comments

@mrdeveloperdude
Copy link

mrdeveloperdude commented Feb 25, 2022

I am trying to hide locust behind nginx using the following location stanza in nginx config:

    # nginx handler for locust
    location /my_path/locust {
        # Trick to avoid nginx aborting at startup (set server in variable)
        set $locust_upstream_server  http://locust-master:8089;
        rewrite                                 ^/my_path/locust/?(.*) /$1 break;
        proxy_pass                          $locust_upstream_server;
        proxy_set_header Host       $host;
    }

You will see that I rewrite all requests that arrive to /my_path/locust to / so that locust will recognize them.

It sort of works, but all the resources loaded from the page somehow wants to fetch from /my_path/static instead of /my_path/locust/static which breaks the whole page.

When looking at the source of the locust page the reason becomes apparent. For some reason resources are prefixed with ./static/*. This is the start of the source for reference:

<!DOCTYPE html>
<html>
<head>
    <title>Locust for locustfile.py</title>
    <link rel="stylesheet" type="text/css" href="./static/css/application.css?v=2.8.2" media="screen">
    <link rel="shortcut icon" href="./static/img/favicon.ico" type="image/x-icon"/>
</head>

Notice how favicon is fetched from ./static/img/favicon.ico for example.

This seems like a strange convention that creates trouble when trying to front locust with a reverse proxy like nginx. I hereby request that resource URLs are converted to be relative. It would simply be a matter of removing the ./ from the resources in question.

I don't mind writing a merge request if that is welcome.

@cyberw
Copy link
Collaborator

cyberw commented Feb 25, 2022

I’m not sure why someone decided on using that format. See if you can find who originally did that (in the git history) and ping them here.

makes sense so change it I guess.

@kurtmckee
Copy link
Contributor

References:

@karol-brejna-i
Copy link
Contributor

The reason for the patch was to be able to have Locust behind K8s' ingress (see PR's discussion). And it helped.
If we provide a recipe for doing that with an absolute path, it would be great and the URLs form can be restored.
I don't feel emotionally attached to the change ;-)

@cyberw
Copy link
Collaborator

cyberw commented May 9, 2022

(as mentioned in #2071 )

The leading ./ in all links looks weird to me. If you can, then try removing it and see if it helps (instead using "regular" relative links without the leading ./)

Doing that could cause issues for k8s users (as mentioned there), but I think it is not really the right solution.

@5imun
Copy link
Contributor

5imun commented Jun 27, 2022

This happens when your url doesn't end with slash so browser removes last slug in the url when using relative urls (like removing filename from filesystem path). Removing ./ will have no effect, it will still behave like relative url.
Without trailing slash:

BASE URL: https://example.com/my_path/locust
RELATIVE URL: ./static/img/favicon.ico
FINAL URL: https://example.com/my_path/static/img/favicon.ico

With trailing slash:

BASE URL: https://example.com/my_path/locust/
RELATIVE URL: ./static/img/favicon.ico
FINAL URL: https://example.com/my_path/locust/static/img/favicon.ico

So easiest way to make it work is to use mandatory slash in your nginx rule like this ^/my_path/locust/(.*) /$1 break, and optional you can add 301 redirect for base url without trialing slash to base url with trialing slash.

I think that this can be fixed by using HTML tag in the html head, but then the question is what would you use for href attribute since you can also have multiple base urls/paths...

@cyberw
Copy link
Collaborator

cyberw commented Jul 7, 2022

Can this issue be considered fixed or is there something more we need to do in locust?

@cyberw
Copy link
Collaborator

cyberw commented Jul 18, 2022

I guess it is fixed

@cyberw cyberw closed this as completed Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants