Next.js Discord

Discord Forum

Server actioin not found when using a Load Balance

Answered
Short-tailed Hawk posted this in #help-forum
Open in Discord
Avatar
Short-tailed HawkOP
Hi, currently I am deploying my company website via coolify, I added 2 ec2`s instances and a AWS Load Balance in front of them, they are working as expected except for server actions, sometimes it does work and other times it just says that it could not locate the server action.

The only way I managed to make it work is by enabling the AWS Loadbalance Sticky Session, which makes the user remain in the same instance via a Cookie with a expired date, but I dont like this aproach.

Is there a way in Nextjs to fix this?
Image
Answered by Short-tailed Hawk
I managed to make it work by using both aproaches, generating a buid ID and setting the Server Actions Encryption Key. Thanks @Asian black bear
View full answer

12 Replies

Avatar
Asian black bear
There is a security feature to prevent server actions running like that, but you can configure that specifically for these cases, I'll try to find the details.
I can't find the source anymore but I have a gut feeling it relates to the build ID which can be made static across different instances and chances are it should help calling the actions via a balancer: https://nextjs.org/docs/app/api-reference/next-config-js/generateBuildId

However, I want to stress, this is an educated guess and not based on personal experience.
Avatar
Short-tailed HawkOP
I just added the new env variable for the new encryption, it did not work 😦
Avatar
Asian black bear
Have you tried to use the same build ID? If that doesn't work either then I have no other suggestions myself anymore.
Avatar
I host behind our LB and there was some setting on the LB configuration for the specific rules that ensured the client stayed pointed toward the same server unless it was down or it timed out. Not sure if thats an option for you. Was the easiest way to fix the issue.
Avatar
Asian black bear
OP mentioned that already, sticky sessions is the term.
Avatar
Oh sorry. I skimmed.
and.... again I skimmed, I see you provided the link to the doc 😅
been a long week
Avatar
Short-tailed HawkOP
I managed to make it work by using both aproaches, generating a buid ID and setting the Server Actions Encryption Key. Thanks @Asian black bear
Answer