Issue with specifying hostname in nextjs app

I am building a next app which redirects the user from the middleware after making some changes to the nexturl. Unfortunately the redirected link is a localhost url, while it should have the hostname given by render.

To specify the hostname to the nextjs app, I used the RENDER_EXTERNAL_URL env variable and passed it to the start cmd for hostname argument

pnpm start --hostname $RENDER_EXTERNAL_URL

This gives the following error

 ⨯ Failed to start server
Error: getaddrinfo ENOTFOUND
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: ''

Please help how can I fix this

Hi there,

Looks like your service is trying to resolve which isn’t a host; it’s a URL. What happens if you use RENDER_EXTERNAL_HOSTNAME instead.

Note, I’m not sure I understand your mentioning of localhost. I don’t see where this is involved, with the information you have provided.


Render Support, UTC+10 :australia:

1 Like

Hey, sorry for the late reply.

I tried the solution, but still got the same error.

==> Running ‘pnpm run start --hostname $RENDER_EXTERNAL_HOSTNAME’

onthemenu-v1@0.1.0 start /opt/render/project/src
next start “–hostname” “
⨯ Failed to start server
Error: listen EADDRNOTAVAIL: address not available
at Server.setupListenHandle [as _listen2] (node:net:1880:21)
at listenInCluster (node:net:1945:12)
at GetAddrInfoReqWrap.doListen [as callback] (node:net:2109:7)

Hi there,

Ah, --hostname on next start defines what host the server will bind to. You don’t want to change this as its default is and this is a requirement for a Render web/private service:

If you still have issues after removing this, please open a ticket directly with us so we can have a closer look at the specific service having issues.


Render Support, UTC+10 :australia: