How to setup https in adonis 4?


Would please clarify on how to use https instead of the default http server?


Hi @mouradghafiri

When you want to use Adonis in production I would not recommend using the default http server.
What I would recommend for a production setup would be using pm2 to run your app as a service, and then use Nginx as a reverse proxy down to your app.

In this setup Nginx would be responsible for serving traffic on port 80 (http) and 443 (https), hence Ngnix would also be responsible for any SSL certificates.

On the other hand you could look into a more managed setup such as Heroku.


In addition to what @madsobel said, you will also need to setup SSL certificate.


You may also need Let’s Encrypt - a free SSL certificates provider.


You can write custom http instance in file server.js, like as:

'use strict'

const https = require('https')
const { Ignitor } = require('@adonisjs/ignitor')

new Ignitor(require('@adonisjs/fold'))

Currently, it’s not work because this fix not released


Are those two lines all that’s necessary? Or are there other guards that we should be aware of?

@virk @romain.lanz This would be a great to add to documentation or recipes :smile:


Yes will add to the recipe