Separate API and admin panel - 404 at loading admin/init

System Information
  • Strapi Version: 3.6.2
  • Operating System: Ubuntu 20.04
  • Database: PostgreSQL on RDS
  • Node Version: 14.16.1
  • NPM Version: 6.14.12
  • Yarn Version: 0.32+git

Hello!

I’m trying to get the following setup running. I want to have the API running on a different server than the admin panel. Goal: EC2 instance #A is serving the API and EC2 instance #B is serving the react app - the admin panel. For the beginning, I tried to get the separation running on just one EC2 machine but failed so far in loading the admin panel.

I have a subdomain api.example.com pointing to EC2#A

My config/server.js looks like:

    module.exports = ({ env }) => ({
        host: env('STRAPI_HOST'),
        port: env('STRAPI_PORT'), 
        url: 'https://api.example.com',
        admin: {
         url: '/',
         serveAdminPanel: false, 
          auth: {
            secret: env('ADMIN_JWT_SECRET'),
          },
        },
      });

STRAPI_HOST=“0.0.0.0”
STRAPI_PORT=“1337”

My /etc/nginx/conf.d/upstream.conf looks like:

# Strapi server
upstream strapi {
    server 127.0.0.1:1337;
}

My activated nginx strapi.conf (/etc/nginx/sites-available) looks like:

server {
   # Listen HTTP
   listen 80;
   server_name api.example.com;

    # Redirect HTTP to HTTPS
    return 301 https://$host$request_uri;
}

server {
        # Listen HTTPS
        listen 443 ssl;
        server_name api.example.com;

include snippets/self-signed.conf;

# Proxy Config
location / {
    proxy_pass http://strapi;
    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;
}

}

If I serve the API via npm run develop and afterward the build directory with http-serve -p 8080
I do see the following 404 GET HTTP:///admin/init 404 (Not Found) if I try to load HTTP://:8080 within a browser. The index.html gets loaded but then it failed to load some I assume react routes at admin/init ?!

So any tips or points to a tutorial walkthrough about how to set up a split of the admin panel and API is more than welcome.

I also had a look at Nginx Proxying | Strapi Documentation

Best regards
Frank

Hi @Spike,

Did you find out how to serve the build directory for serving the admin panel separately from the API? Because I have the same question.

Best Regards.