Hosting several Strapi on the same server using NGINX with Subfolder unified conf

System Information
  • Strapi Version: 3.6.8
  • Operating System: Ubuntu 20.04
  • Database: MySQL 8
  • Node Version: v14.18.2
  • NPM Version: 6.14.15
  • Yarn Version: 1.22.15


I’m trying to host several strapi apps on a same server and domain, using Nginx with subfolder unified conf, to have something like this :

So far I did this : 2 nginx configs, which are in sites-availables with symlink in sites-enables
They both have the same config, unless for the upstream and location, where I change the name and/or the port.

What is strange here is if I remove one of the conf from sites-enabled both of websites are working independently, but when I have the 2 conf enabled, then one of them get 403 forbidden.

Here is my Nginx conf for my first site:

# path: /etc/nginx/sites-available/strapi_blue.conf

# Strapi server
upstream strapi_blue {

server {
    # Listen HTTP
    listen 80;

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

server {
    # Listen HTTPS
    listen 443 ssl;

    # SSL config
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    # Static Root
    location / {
        root /var/www/strapi;

    # Strapi API and Admin
    location /blue/ {
        rewrite ^/blue/?(.*)$ /$1 break;
        proxy_pass http://strapi_blue/;
        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;

For the 2nd site, the conf is the same with those differences :

# Server
upstream strapi_red {

    # API and Admin
    location /red/ {
      rewrite ^/red/?(.*)$ /$1 break;
      proxy_pass http://strapi_red/;

When enabling the 2 confs, I got red working fine, but blue giving a 403 forbidden with the following error in nginx logs : directory index of "/var/www/strapi/blue/" is forbidden. (Checked permissions, they are ok)

When enabling only 1 of the confs, the corresponding site is well served and running fine.

Any clue ?

Ok guys,
Finally fixed the issue.

The problem is that I had 2 conf, both with the same domain.
Had to put all subfolders location directives in an unique server block, instead of one per site