Skip to content

Deployment Overview of Strapi on Server

Prerequisites and Basic Requirements

The server must meet the following requirements to host the Strapi application and its associated services:

  • Operating System: Ubuntu (compatible with the Docker installation role).

  • Privileges: Root or sudo access is required to create directories, manage Docker, and configure the firewall.

  • Domain: The deployment utilizes the hostkey.in zone.

  • Ports:

  • Port 1337 is used for the internal Strapi application.

  • Port 5432 is used for the PostgreSQL database.

  • Ports 80 and 443 are utilized by the Nginx proxy for HTTP and HTTPS traffic.

FQDN of the Final Panel

The application is accessible via the following Fully Qualified Domain Name (FQDN) structure:

strapi<Server ID>.hostkey.in:1337

Note: The actual external access may be routed through the Nginx proxy on standard ports (80/443) depending on the proxy configuration, while the direct container port is 1337.

File and Directory Structure

The deployment utilizes the following directories for application data, configuration, and certificates:

  • /opt/strapi: Primary volume for the Strapi application data and code.

  • /root/nginx: Directory containing the Nginx and Certbot docker-compose.yml configuration.

  • /etc/letsencrypt: Directory mounted for SSL/TLS certificates managed by Certbot.

  • /data/nginx/user_conf.d: Directory for custom Nginx user configurations.

  • /data/nginx: Directory containing the environment file nginx-certbot.env.

  • /var/lib/postgresql/data: Directory for PostgreSQL persistent data storage.

Application Installation Process

The application is deployed using Docker containers. The installation includes the Strapi instance and a PostgreSQL database container, orchestrated within a dedicated Docker network.

  • Strapi Image: docker-repo.hostkey.com/docker-anonymous/strapi:latest

  • PostgreSQL Image: postgres:15

  • Docker Network: strapi_network

The deployment process involves:

  1. Creating the necessary volume directory at /opt/strapi.

  2. Establishing the Docker network strapi_network.

  3. Launching the PostgreSQL container with specified environment variables.

  4. Launching the Strapi container connected to the same network and database.

Databases

The application uses a PostgreSQL database for data persistence. The database is hosted within a Docker container named strapi-db.

  • Database Host: strapi-db

  • Database Port: 5432

  • Database Name: strapi

  • Database User: strapi_user

  • Database Password: strapi_password

  • Storage Location: Data is persisted in /var/lib/postgresql/data on the host.

The Strapi container connects to the database using the following environment variables:

  • DATABASE_CLIENT: postgres

  • DATABASE_HOST: strapi-db

  • DATABASE_PORT: 5432

  • DATABASE_USERNAME: strapi_user

  • DATABASE_PASSWORD: strapi_password

Docker Containers and Their Deployment

The system utilizes the following Docker containers:

  1. strapi-db

  2. Image: postgres:15

  3. Restart Policy: always

  4. Network: strapi_network

  5. Volume: Maps /var/lib/postgresql/data to /var/lib/postgresql/data inside the container.

  6. Ports: Exposes 5432 mapped to host port 5432.

  7. strapi

  8. Image: docker-repo.hostkey.com/docker-anonymous/strapi:latest

  9. Restart Policy: always

  10. Network: strapi_network

  11. Volume: Maps /opt/strapi to /srv/app inside the container.

  12. Ports: Exposes 1337 mapped to host port 1337.

  13. nginx (Proxy and SSL)

  14. Image: jonasal/nginx-certbot:latest

  15. Restart Policy: unless-stopped

  16. Network Mode: host

  17. Volumes:

    • nginx_secrets mapped to /etc/letsencrypt

    • /data/nginx/user_conf.d mapped to /etc/nginx/user_conf.d

  18. Configuration File: /root/nginx/compose.yml

Proxy Servers

The deployment includes an Nginx reverse proxy with automatic SSL certificate management via Certbot.

  • Proxy Image: jonasal/nginx-certbot:latest

  • Email for Certbot: [email protected]

  • Configuration Location: /root/nginx/compose.yml

  • Environment File: /data/nginx/nginx-certbot.env

  • Volume Mounts:

  • nginx_secrets (external volume) mounted to /etc/letsencrypt.

  • Host directory /data/nginx/user_conf.d mounted to /etc/nginx/user_conf.d.

  • Network Mode: The Nginx container runs in host network mode.

The proxy handles traffic forwarding and SSL termination for the Strapi application.

Permission Settings

File and directory permissions are configured as follows:

  • Strapi Volume (/opt/strapi):

  • Owner: 1000 (User ID)

  • Group: 1000 (Group ID)

  • Mode: 0755 (rwxr-xr-x)

  • Nginx Directory (/root/nginx):

  • Owner: root

  • Group: root

  • Mode: 0755

  • Docker Compose File (/root/nginx/compose.yml):

  • Owner: root

  • Group: root

  • Mode: 0644

Location of Configuration Files and Data

The key configuration files and data locations are:

File/Directory Path Description
/root/nginx/compose.yml Docker Compose configuration for Nginx and Certbot.
/data/nginx/nginx-certbot.env Environment variables for the Nginx/Certbot container.
/opt/strapi Persistent storage for Strapi application data.
/var/lib/postgresql/data Persistent storage for PostgreSQL database data.
/etc/letsencrypt Storage for SSL/TLS certificates (via volume mount).

Available Ports for Connection

The following ports are exposed and available for connection:

  • Port 1337: Direct access to the Strapi application container.

  • Port 5432: Direct access to the PostgreSQL database container.

  • Port 80: HTTP traffic handled by the Nginx proxy.

  • Port 443: HTTPS traffic handled by the Nginx proxy with SSL.

Starting, Stopping, and Updating

The services are managed using Docker commands.

Nginx Proxy Management: To start, stop, or update the Nginx proxy and Certbot services, execute commands from the /root/nginx directory:

cd /root/nginx
docker compose up -d
docker compose down
docker compose pull
docker compose up -d

Strapi and Database Management: The Strapi and database containers are managed directly via Docker commands:

# Start containers
docker start strapi strapi-db

# Stop containers
docker stop strapi strapi-db

# Restart containers
docker restart strapi strapi-db

# Update images
docker pull docker-repo.hostkey.com/docker-anonymous/strapi:latest
docker pull postgres:15
docker update strapi strapi-db

The restart_policy is set to always for both the Strapi and strapi-db containers, ensuring they automatically restart upon system reboot or crash.

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×