NGINX - The Panel cannot connect to the API

Hey team,

I have a NGINX server with PHP 7.4 running and unfortunately can’t connect to the API:

https://www.theelephant.io/panel/login

Local all fine, but remote server not.

Config file:

<?php
# Kirby Configurations
return [
'panel' =>[
'install' => true],
# Kirby Settings
'debug' => false,  # Enable Debug Mode
'home'  => 'home', # Change the slug for the homepage

# Markdown Field Configurations
'community.markdown-field.font' => [
    'family'  => 'sans-serif',
    'scaling' => true,
    'size'    => 'small',
],
'community.markdown-field.modals'     => true,
'community.markdown-field.blank'      => false,
'community.markdown-field.invisibles' => false
];

Unfortunately I am no expert to config NGINX accordingly, can you pls. help? :slight_smile:
Thank you and warm regards
Sebastian

Hey, welcome to the forum.

I’m not familiar with nginx either, but there are already quite a few configs scattered around the forum, e.g. here: Error 500 on Panel (Nginx, PHP 7.3) - #20 by nikken

Edit: Doesn’t seem to be a specific Nginx problem, I see this error in console

Hi texnixe,

thank you a lot for the fast reply :slight_smile:

Might it be due my cloudflare integration - I forgot to mention?

Probably, maybe this help: https://support.cloudflare.com/hc/en-us/articles/200308847-Using-cross-origin-resource-sharing-CORS-with-Cloudflare

Hi Texnixe,

I think I have an idea :wink:

The problem is, that the API will be triggered without www. and the actual page is running under www.

This leads to the cross origin right?

Can we move the panel from

https://****.io/panel

to

https://www.****.io/panel

I assume then the API will also be triggered under
https://www.****.io/api/system?view=panel

instead

https://****.io/api/system?view=panel

You have to enfore www via your server config.

You could first try if it has any effect if you set your base url in the site/config/config.php file.

It is strangely not working when I switch to www again, I need to discuss with Cloudflare how to flush the header cache - then this should be solved.

BUT:

Why is the api triggered not under www.?

And: How can I change the base URL and use the same files in the local installation?

Right now I have all files locally - the are pushed to github and from there to the server :slight_smile:

Kirby allows you to define different config files per domain, see https://getkirby.com/docs/guide/configuration#multi-environment-setup

I’d assume that’s a problem with your redirect not working for all URLs.

I really appreciate your fast support :slight_smile:
Unfortunately it is not working :frowning_face:

config.www.theelephant.io.php
<?php

# Kirby Configurations
return [
'url' => 'https://www.theelephant.io',
'panel' =>[
  'install' => true],
# Kirby Settings
'debug' => false,  # Enable Debug Mode
'home'  => 'home', # Change the slug for the homepage

# Markdown Field Configurations
'community.markdown-field.font' => [
    'family'  => 'sans-serif',
    'scaling' => true,
    'size'    => 'small',
],
'community.markdown-field.modals'     => true,
'community.markdown-field.blank'      => false,
'community.markdown-field.invisibles' => false
];

Cloudflare has a wildcard forward

Still it tries to use the non-www api call instead of the www - as you can see in the errors :frowning:
Do you have any idea?