2

I have nginx in entry point to server. which handle SSL connection and send HTTP request in /api/v1/ to HAproxy for balancing. this is my nginx config:

    location /api/v1/ {
        proxy_pass http://127.0.0.1:8585/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

and HAproxy config:

frontend haproxy_entry
    bind *:8585
    mode http
    log global
    acl is_api url_beg /api/v1/
    use_backend api if is_api

the problem I have is that I should pass /api/v1/ path twice. if I request https://servername.com/api/v1/ haproxy would not handle this properly but for :https://servername.com/api/v1/api/v1/ it's ok. how can i fix this?

1
  • 1
    Your Nginx reverse proxy is stripping off /api/v1/. Are you saying that it should pass the request transparently? If so, just remove the trailing / from the proxy_pass statement. Jan 25, 2019 at 11:01

1 Answer 1

2

The proxy_pass statement includes an optional URI which is used to modify the URL before passing it upstream.

In your question, the proxy_pass statement includes a URI of /, which in conjunction with the location value, causes the /api/v1/ part of the original URL to be substituted for /.

For example: https://example.com/api/v1/foo is translated to http://127.0.0.1:8585/foo.

It seems that you do not need this. To turn off the feature, simply remove the URI part.

For example:

location /api/v1/ {
    proxy_pass http://127.0.0.1:8585;
    ...
}

See this document for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .