Project-Wide Rate Limiting and NGINX Reverse Proxy Setup

AnonymousTRIAL

a year ago

Project ID: 55016719-04a1-4c9f-a9dc-e42d9e01c185

I am currently hosting several microservices in the same railway project, including an analytics service, an auth service, and others. During periods of high traffic, some endpoints that perform expensive database queries can cause significant load. To mitigate this, I would like to implement project-wide rate limiting rather than implementing it at the service level.

I have set up an NGINX reverse proxy in my project to utilize its rate limiting - however, I am encountering an issue where the NGINX instance is unable to resolve the internal Railway urls. The error message I am receiving is:

```
[emerg] 11#11: host not found in upstream "analytics.railway.internal" in /etc/nginx/nginx.conf

I am using the Railway internal URLs in the following format within my NGINX configuration

http://${{analytics.RAILWAYPRIVATEDOMAIN}}:${{analytics.PORT}}
```

I have also seen the workaround for Alpine-based images using private networking. However, this issue persists across services written in different languages, including Python.

This leaves me with two questions

  1. How can I configure NGINX to resolve the internal Railway URLs

  2. Any best practices for setting up project-wide rate limiting using NGINX or any other recommended approach on the Railway platform?

0 Replies

AnonymousTRIAL

a year ago

Here is my nginx conf it it would be helpful

events {}

http {
    server {
        listen 80;

        location /analytics/ {
            proxy_pass ${ANALYTICS_URI}/;
            proxy_set_header Host ${HOST};
            proxy_set_header X-Real-IP ${REAL_IP};
            proxy_set_header X-Forwarded-For ${FORWARDED_FOR};
            proxy_set_header X-Forwarded-Proto ${FORWARDED_PROTO};
        }

        ...
    }
}

a year ago

  1. its a tad tricky, and imo not worth it

  2. i would personally go with caddy


AnonymousTRIAL

a year ago

Awesome, I'll take a look at Caddy. Thank you!


a year ago

this template is not exactly what you want, but i think it would be a good jumping off point -