Tips: how to fix Peertube no more working when updating to NodeJS 18

When upgrading NodeJS from v16.x to v18.x, in some case, your Peertube server won’t respond anymore.

This is because of a change in IPv4/IPv6 handling in NodeJS 18. Now, the resolution of localhost is IPv6 first.

So, if you have this in your nginx config:

upstream backend {

And this in your production.yaml:

  hostname: 'localhost'
  port: 9000

(these were the values that where in the official Peertube documentation some times ago)

In such case, you will get a « 502 Bad Gateway » when trying to connect to your Peertube.
This is because the localhost value in the Peertube configuration makes node listen only on IPv6!

This can be confirmed using telnet on your server:

$ telnet 9000
Unable to connect to remote host: Connection refused

$ telnet ::1 9000
Trying ::1...
Connected to ::1.
Escape character is '^]'.

The easiest way to fix is to change your production.yaml to use ‹ › as hostname.
By the way, the official Peertube production.yaml uses now this value:

And don’t know when and why this was changed in the official files.