1

I am trying to rewrite proxy_read_timeout for a specific route that sends requests to Replicate that has longer response times. If the AI model is cold, it takes more than 1 minute to respond and Nginx throws 504 timeout error.

Below is my current nginx config. It throws Cannot POST / error for all requests to /api/ai/. All requests to /api/ are working fine.

What am I doing wrong?

        location /api/ {
            proxy_pass http://localhost:3000/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect /api/ /;

        }
          # Replicate
        location /api/ai {
            proxy_pass http://localhost:3000/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_connect_timeout 120s;
            proxy_read_timeout 120s;
            proxy_send_timeout 120s;
        }
1
  • Did you mean location /api/ai/ (with the trailing /)? Commented Aug 14, 2024 at 12:17

1 Answer 1

1

In the first location block, requests to a URL like /api/foo/ are sent upstream to http://localhost:3000/foo/ effectively removing the /api prefix.

Assuming that you wish the same transformation in the second location block, you need to make similar changes to both the location and proxy_pass statements.

For example:

location /api/ai {
    proxy_pass http://localhost:3000/ai;
    ...
}

So requests to the URL /api/ai/ are sent upstream to http://localhost:3000/ai/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.