How to setup https in adonis 4?


#1

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


#2

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.


#3

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


#4

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


#6

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'))
  .appRoot(__dirname)
  .fireHttpServer(https.createServer)
  .catch(console.error)

Currently, it’s not work because this fix not released https://github.com/adonisjs/adonis-ignitor/commit/703ef289233fda06ca7fbcdfc23bc29eb793b8d7


#7

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:


#8

Yes will add to the recipe