Can this nginx config work with traefik?

Hello, I got Traefik to work with some applications, but still got a problem with one of them. The software, which delivers the GUI which I want to proxy has some open issues with fixes, but I only got an example for a nginx config. It would be great if you could help me implement the following nginx config in Traefik.

location /arango/ {
    proxy_pass http://arangodb/;
    proxy_redirect ~^/(.*) http://$http_host/arango/$1;
    proxy_set_header X-Script-Name /arango;

Thanks in advance c:

I am confused. Why you are using nginx and traefik together?

Sorry if this was unclear. I am not using nginx. The above line of code, is the only solution I could find for a problem I am experiencing. That's why I am asking if the above code can be implemented in traefik.

Helo @Likqez

Honestly speaking I have no experience with ArangoDB but you can try to use TCP / UDP routers on Traefik. Here is the detailed documentation: Routers - Traefik that should help you to start with building the initial configuration.

You can use add header using Middleware: Headers to add X-Script-Name - here is the documentation of how to work with that:

Hope that helps.

Thank you,

Could not agreed more with @jakubhajek
Middleware Headers are great and to be honest you should be able to implement it with Traefik.
I could replace all nginx services for traefik onto jenkins, gocd , python / javascripts app with better performance.

I already got something to work with now. This is my current configuration:

Although the request gets proxied to the arango container, I am receiving this error:

{"error":true,"code":404,"errorNum":404,"errorMessage":"unknown path '/arango'"}

Yeah, the problem persists because of an ArangoDB issue, but still should be doable.
Maybe with the 2nd line from nginx config, but i don't know how to do this in traefik.

Its a tricky one.
You could play with the headers adding more like scheme, permanent, X-Forwarded-Proto or X-Forwarded-Host, etc.



and see what happends.

The suggested headers didn't do a thing. I already tried stripping the prefix, but that will redirect me to instead ofàrango/_db/_system/_admin/aardvark/.

Do you know how I can strip the prefix but still redirect to /arango?
I think that would be the same as the proxy_redirect in nginx conf.

If you want to redirect the request to a different location, try redirectregex and have fun with regular expressions :slight_smile:

I think I should work....

1 Like

Using a combination of redirectregex and stripprefix I finally got i to work as intended!

This is the configuration I used:

       - "traefik.enable=true"
       - "traefik.http.routers.arango.entrypoints=websecure"
       - "traefik.http.routers.arango.rule=Host(``) && (PathPrefix(`/arango`) || PathPrefix(`/_db`))"
       - "traefik.http.routers.arango.tls=true"
       - ""
       - "traefik.http.middlewares.arango-header.headers.customrequestheaders.X-Script-Name=/arango/"
       - "traefik.http.middlewares.arango-strip.stripprefix.prefixes=/arango"
       - "traefik.http.middlewares.arango-redirectregex.redirectregex.regex=*)"
       - "traefik.http.middlewares.arango-redirectregex.redirectregex.replacement=$${1}"
       - "traefik.http.routers.arango.middlewares=arango-header, arango-redirectregex, arango-strip"

Also, I learned that middlewares are ordered and applied one after one, otherwise I would create an endless redirection loop.

Thanks for pushing me into the right directions :slight_smile:

PS: The Regex was fun :stuck_out_tongue:


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.