Please add a trailing slash at the end of proxy_pass URI as http://rails_app:4000/
Adding the trailing slash tells NGINX to strip the /api prefix from the request URL before passing it to the backend service. This way, if a client requests /api/posts, it will be proxied to http://rails_apps:4000/api