0

I'm trying to pass the API requests to the backend with NGINX reverse proxy.

When I send a get request to /api/testdata, it sends a request to {frontendURL}/api/testData which returns with 301(redirect) status code. After that It redirects the request to the correct url {backendURL}/api/testData.

Network tab network tab 1 network tab 2 network tab 3

nginx config:

server {
    listen 80 default_server;
    listen [::]:80 default_server;



    root /usr/share/nginx/html;

    server_name _;

    location /health {
            access_log off;
            add_header 'Content-Type' 'application/json';
            return 200 '{"status":"Healthy"}';
    }

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    location /api {
        proxy_pass http://localhost:3001; 
        proxy_redirect off;
    }

Can I somehow prevent the redirect request so that only one request goes out? Or is this the normal behaviour?

szgezu
  • 1
  • 1
  • either tell the real url or share the output of curl – djdomi Aug 24 '23 at 16:44
  • @djdomi I can send some picture about the network tab. [Redirected request](https://i.stack.imgur.com/8Rq8b.png) [Request to the redirected url](https://i.stack.imgur.com/5OUpN.png) [Response](https://i.stack.imgur.com/60S8J.png) – szgezu Aug 24 '23 at 17:28
  • If I use curl without -L on {frontendUrl}/api/testdata, it doesn't send back anything because the request is just redirected. With -L, it sends the data back correctly. – szgezu Aug 24 '23 at 17:30
  • You first request goes to `gwk-frontend`. I guess it's some other server. – Alexey Ten Aug 25 '23 at 09:21
  • remind to share the output by edit the question instead of using the commantary section ;) – djdomi Aug 26 '23 at 11:38

0 Answers0