Frontend of Plone6 cannot accsess api of backend on nginx

I installed Plone6 as a package with the following documentation.

My environment is as follows.
server : ubuntu server 22.04
nginx : 1.26.1

I wrote the nginx configuration file using the following documentation.

my nginx conf :

upstream backend {
  server 127.0.0.1:8080;
}
upstream frontend {
  server 127.0.0.1:3000;
}

server {
    server_name my_site.com;
    listen 80 default_server;

    root /var/www/html;

    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
  listen 443 ssl;
  http2 on;
  server_name my_sites.com;
  ssl_certificate /etc/letsencrypt/live/my_sites.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/my_sites.com/privkey.pem;
  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:10m;
  ssl_session_tickets off;
  ssl_protocols TLSv1.3 TLSv1.2;
  ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256';
  ssl_prefer_server_ciphers off;

  location ~ /api($|/.*) {
      rewrite ^/api($|/.*) /VirtualHostBase/http/$server_name/Plone/++api++/VirtualHostRoot/$1 break;
      proxy_pass http://backend;
  }

  location ~ / {
      location ~* \.(js|jsx|css|less|swf|eot|ttf|otf|woff|woff2)$ {
          add_header Cache-Control "public";
          expires +1y;
          proxy_pass http://frontend;
      }
      location ~* static.*\.(ico|jpg|jpeg|png|gif|svg)$ {
          add_header Cache-Control "public";
          expires +1y;
          proxy_pass http://frontend;
      }

      proxy_set_header        Host $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_redirect http:// https://;
      proxy_pass http://frontend;
  }
}

I can access frontend but it shows the following.

And if I login with admin:admin, I get the following error and cannot go any further.

I know that problems similar to this have been discussed several times on this forum. However, it does not work using any of the methods.
I would be very grateful for your help.

Thank you.

Try something like this for the api part:

  location ~ /\+\+api\+\+($|/.*) {
      rewrite ^/\+\+api\+\+($|/.*) /VirtualHostBase/https/$http_host/Plone/++api++/VirtualHostRoot/$1 break;
      proxy_pass http://backend;
  }

Note the use of "https", not sure it is absolutely needed but it works for my usecase.

1 Like

Thank you!
I'II try it!

Also check the server_name...
It is set my_sites.com in some places and my_site.com in another place.