Hi everyone, i’m trying to configure strapi to be served at /cms path.
As described in documentation, i modified server.js setting url: “/cms”
I rebuild the admin portal and when i run yarn develop i see in the logs:
To manage your project 🚀, go to the administration panel at:
http://localhost:1337/cms/admin
To access the server ⚡️, go to:
http://localhost:1337/cms
when i open the link in the browser, an html page is returned. This page invokes http://localhost:1337/cms/admin/init returns html code (same as index) instead of json and the page breaks.
Also none of the api seems working, i always get a 404
On it’s own Strapi can’t do what you are trying to do (you could change the API prefix but that won’t modify the route to the admin, file uploads, or various other endpoints).
I tried with nginx and I’ve been able proxy the apis.
The problem is the admin panel. Both admin page (/cms/admin) and apis (ex. /csm/admin/init) start with /cms/admin so the nginx rule present in the documentation applies to both, breaking the FE.
I had to change the url setting in admin.js to something different. Then in my nginx configuration i created another rule to handle the new admin url disabling the rewrite
Hello, I have wasted a lot of time trying to do this with strapi 4.1.7
Thank you for sharing the solution
To recap if someone else needs to host strapi in subfolder path :
You need to add the path in ./config/server.js : url: env('STRAPI_URL', ''),
Add a specific path for strapi admin panel in ./config/admin.js : url: env('STRAPI_ADMIN_URL', '/admin'),
Add two nginx location, one for each url with only the root location requiring a rewrite
don’t forget to rebuild strapi…
I think the same issue exist with other reverse proxy such caddy or haproxy since it is a strapi configuration issue.
Maybe the documentation at Nginx Proxying - Strapi Developer Docs should be updated ?
The main trick is that url in ./config/server.js should be set to a needed value at build time, it’s not picked up at runtime.
For example, if you want to make it configurable from environment like url: env('BASE_URL'), then your BASE_URL should be available when you’re running npm build.
In case of building a Docker image one can set BASE_URL as follows: