dazmoob / strapi-openlitespeed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strapi on OpenLiteSpeed

Why do it simple when you can do it weird?

Why would you do that?

When it comes to web servers, it's usually a question of nginx or apache. Recently, it might not even be a question anymore considering tools like netlify or vercel handle almost all backend configuration on their own.

However, when installing Strapi the regular way, we need to choose. I chose OpenLiteSpeed.

Benefits of OpenLiteSpeed

  • it has a graphical interface
  • it has a good documentation
  • http/3 (quic) support out of the box
  • and more features

Installing OpenLiteSpeed

OpenLiteSpeed can be installed on a server (ubuntu/debian/centOS) through official repositories or using a pre-configured image like Digital Ocean offers.

I tried both and everything works fine.

Virtual host configuration

Basic tab

  • login into your admin panel, usually accessible on port 7080 (your.ip.address:7080)
  • add a new virtual host following the official guide
  • the Virtual Host Name can be anything like "strapi"
  • the Virtual host root can be the folder where strapi lives
  • for the config file, you can use this string: $SERVER_ROOT/conf/vhosts/$VH_NAME/$VH_NAME.conf
    It uses server variables to put the conf inside /usr/local/lsws/conf/vhosts/strapi/strapi.conf When you save, OLS will ask you if it should create the .conf file for you, say yes.

General tab

  • the Document Root does not matter, I set it to the public strapi folder
  • set the Domain name to your strapi domain

External App tab

  • add a new 'Web Server' in the external app tab
  • give it an obvious name
  • set the address to strapi's default 0.0.0.0:1337
  • you can define environment variables in Environment instead of a .env file if you wish

Context tab

  • add a new 'Proxy' context
  • use the root / for the 'URI' field
  • select your previously created web server form the list
  • you can set headers if you want in the Header Operations field
  • allowed access to everyone with * inside Access Allowed

SSL tab

Here you can define a TLS certificate to be used by OLS for your domain.

Listener configuration

On the listeners window bind your virtual host to both http and https (ssl) listeners.

It’s a pretty straightforward process. Or so I thought.

In order to serve both ipv4 and ipv6 LiteSpeed recommends to use separate listeners. However, I ran into some problems trying to configure separate IPv4/IPv6 listeners so here's how to do it with one.

General tab

  • on the Address Settings, choose [ANY] IPv6 for the IP Address field.
  • the Port field depends on http/https (80/443) but be sure to do both listeners.

On the Virtual Host Mappings, add a new host and choose your Strapi virtual host from the drop-down. In order to listen to ipv4 and ipv6, we need to specify both IP adresses and use a particular syntax for the ipv4 by prepending it with ::FFFF: as such: strapi.yourdomain.tld, ::FFFF:IPV4, IPV6

Do the same for the secure listener on port 443

Deploying Strapi

Now that the server is ready, we can deploy strapi. I followed the official guide. It's basically NODE_ENV=production yarn build and NODE_ENV=production yarn start

It's possible (and recommended) to automate this with pm2.

We’re done

Strapi should be accessible through its domain.
Don’t forget to perform a graceful restart of OpenLiteSpeed and close port 7080 when you’re done with the admin panel.

About