Vagho
Vagho

Reputation: 117

NGINX : proxy_pass with regex and rewrite

i have this NGINX location in my default.conf

   location /api-gateway/ {
       proxy_http_version 1.1;
       proxy_connect_timeout 75s;
       proxy_read_timeout 100s;
       client_max_body_size 100m;
       proxy_set_header Host test.domain.com;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Host $host;
       proxy_set_header X-Forwarded-Port $server_port;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_buffering off;
       proxy_buffers 16 8k;
       proxy_buffer_size 4k;
       proxy_max_temp_file_size 0;
       rewrite ^/api-gateway/(.*)$ $1 break;
       proxy_pass http://ingress-srv; # ingress-srv is an upstream
    }

here is an example of the request that is coming to my NGINX server: http://demo.domain.com/api-gateway/service/v1/metrics

i need to do the below

i can not make it work ..

Upvotes: 1

Views: 7094

Answers (1)

jwg
jwg

Reputation: 5847

Instead of

proxy_pass http://ingress-srv; # ingress-srv is an upstream

try doing (notice the slash):

proxy_pass http://ingress-srv/; # ingress-srv is an upstream

You can take out the rewrite directive.

As Oscar Wilde said "I was working on nginx.conf all the morning, and took out a comma. In the afternoon I put it back again."

Upvotes: 5

Related Questions