Deploy Strapi Admin Panel using Laravel Forge

System Information
  • Strapi Version: 3.4.4
  • Operating System:
  • Database: mySql
  • Node Version: 14.1.0
  • NPM Version: 6.14.8
  • Yarn Version:

I am having issues getting my straps admin panel to deploy using Laravel Forge.

server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url: env('APP_URL'),
});

.env (minus sensitive info)

APP_URL=http://admin.example.com
HOST=admin.example.com
PORT=1337
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306
DATABASE_NAME=strapi_admin
DATABASE_USERNAME=strapi_admin
DATABASE_SSL=true
NODE_ENV=prod

database.js

module.exports = ({ env }) => ({
    defaultConnection: 'default',
    connections: {
        default: {
            connector: 'bookshelf',
            settings: {
                client: 'mysql',
                host: env('DATABASE_HOST', '127.0.0.1'),
                port: env.int('DATABASE_PORT', 3306),
                database: env('DATABASE_NAME', 'strapi-admin'),
                username: env('DATABASE_USERNAME', 'root'),
                password: env('DATABASE_PASSWORD', ''),
                ssl: env.bool('DATABASE_SSL', false),
            },
            options: {}
        },
    },
});

nginx config (minus sensitive info)

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/admin.example.com/before/*;
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name admin.example.com;
    server_tokens off;
    root /home/forge/admin.example.com/public;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    charset utf-8;
    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/admin.example.com/server/*;
    location / {
        proxy_pass path_to_server:1337;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    access_log off;
    error_log  /var/log/nginx/admin.example.com-error.log error;
    location ~ /\.(?!well-known).* {
        deny all;
    }
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/admin.example.com/after/*;

With all this directly on the server we can run npm install, npm build, and npm start with no errors and if I go to https://admin.example.com it says the server is running but when trying to go to https://admin.example.com/admin it just spins and never loads.

I do get a console error but not sure if its related

console error

VM9:1 Mixed Content: The page at 'https://admin.example.com/admin' was loaded over HTTPS, but requested an insecure resource 'http://admin.example.com/admin/init'. This request has been blocked; the content must be served over HTTPS.

Any help on this would be greatly appreciated. Thanks!

This needs to be https and rebuild the admin

Looks like that fixed it, thank you!

2 Likes