I’ve managed deploying my Strapi app on Fly.io, connected to a PostgreSQL database on Supabase.
I’ve followed this Strapi guide, but it seems a little bit outdated so I made some custom edits on my setup.
It… sometimes work, but I regulary get 502 bad gateway
errors (after one minute).
It feels like the app was idle. After a while, I start to get responses (a few seconds) and it works. A few hours later, it does not response again.
About my setup
The default port in Strapi is 1337.
But Fly.io now charges 2$/mo to use custom ports.
Since I’m a hobby user, I then need to use the “free” ports, which are 80 and 443.
database.js
module.exports = ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: env('DATABASE_HOST','localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME'),
user: env('DATABASE_USERNAME','postgres'),
password: env('DATABASE_PASSWORD'),
schema: env('DATABASE_SCHEMA', 'public'), // Not required
ssl: {
rejectUnauthorized: env.bool('DATABASE_SSL_SELF', false),
},
},
debug: false,
},
});
also tested with
ssl: false
fly.toml
[[services]]
http_checks = []
internal_port = 80
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
[env]
PORT="80"
dockerfile
# Expose the Strapi port
EXPOSE 80
It seems that some other users have this problem on Fly.io + Supabase.
Someone says here
that would mean the connection gets closed before response headers
are fully sent back from your app.
Maybe this is related to this comment, but I don’t know how to do that:
Should you encounter a “bad gateway” error, your system may be denying NGINX due to SELinux rules. You can verify this by checking the NGINX logs at
/var/log/nginx/error.log
and looking for “Permission denied”.According to Stack Overflow, the issue can typically be resolved with the following command. This allows NGINX to make network connection on your system:
sudo setsebool -P httpd_can_network_connect 1
Can anyone help ? Thanks !