Proxied Strapi + NextJS with Nginx is not working well

I have a NextJS frontend and a Strapi backend running on an Ubuntu box proxied with Nginx. I have set /strapi subfolder as the location for all strapi requests as per the following config:

location /strapi/ {
rewrite ^/strapi/?(.*)$ /$1 break;
proxy_pass http://localhost:1337;
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;
}

location / {
proxy_pass http://localhost:3000;
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;
}

This works fine for proxying all backend requests, and works locally on my machine, as Nginx strips away /strapi and redirects all queries to /api/articles, for example.

However, this fails on the frontend side - Nginx is stripping away /strapi from URL’s correctly, but for some reason the essential scripts are still located at /strapi/admin and so the panel doesn’t get loaded.
GET
https://mydomain.com/admin/runtime~main.6e4d1d4c.js
[HTTP/1.1 404 Not Found 168ms]

GET
https://mydomain.com/admin/main.8b078a8a.js

This topic has been created from a Discord post (1226650799195553922) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

I have a NextJS frontend and a Strapi backend running on an Ubuntu box proxied with Nginx. I have set /strapi subfolder as the location for all strapi requests as per the following config:

location /strapi/ {
rewrite ^/strapi/?(.*)$ /$1 break;
proxy_pass http://localhost:1337/;
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;
}

location / {
proxy_pass http://localhost:3000/;
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;
}

This works fine for proxying all backend requests, and works locally on my machine, as Nginx strips away /strapi and redirects all queries to /api/articles, for example.

However, this fails on the frontend side - Nginx is stripping away /strapi from URL’s correctly, but for some reason the essential scripts are still located at /strapi/admin and so the panel doesn’t get loaded.
GET
https://mydomain.com/admin/runtime~main.6e4d1d4c.js
[HTTP/1.1 404 Not Found 168ms]

GET
https://mydomain.com/admin/main.8b078a8a.js

this not going to work like that

you need some solid route like you do:
/strapi

and your api should be:
/strapi/api

the reason for this all core stuff like plugins and what’s so ever would use:
/strapi

if you want to see exactly you can check yarn strapi routes:list

to see all the routes you have to remap, if you want it that way