Responses to the discussion on Github
Collaborator
@amaneshi the url key in the server.js
doesn’t change the prefix path on the backend, only within the admin. So when it’s set since react is CSR it tries to connect to the backend via the url provided (which would be proxied by Nginx). With that key set, you won’t be able to access the backend on localhost anymore and will need to use a proxy.
Can you provide your Nginx config, or does your config match the example in the sub-folder-unified nginx config docs?
Collaborator
Something to note from the example I posted above:
rewrite ^/api/(.*)$ /$1 break;
<— This line cuts out the /api
prefix before proxying the request to the Strapi backend.
Author
Thank you for quick response!
Yes, now my NGINX configuration set as in docs article that you provided. And I aware of Nginx rewrite instructions (tried it already).
But take a closer look at my problem/bug - I need use URL parameter to serve frontend on root location (I mean “domain/”) and pass all requests that have prefix “/api” to proxy for strapi.
If I use url - I dont need rewrite at all (I assume this, maybe I wrong), and all requests (that I saw in network tab) to serve static admin panel files starts with “/api” prefix and if I use rewrite rule that cut this prefix - then this static files cant be found by server (as webpack serve files with prefix).
From other side - if I not use URL parameter - I can use rewrite but as all requests serve from root path (internally by strapi) I can’t write proxy config to separate frontend and backend location sections.
About current BUG: as you can see on screenshot - when I start server on localhost static files load as expected but last request (as I described in first message) don’t include “/api” prefix and return wrong answer (moreover, there should be 404 error!)

If I understand something wrong - advice me please how correctly locate frontend (angular) and backend (strapi) on same server with Nginx?
Collaborator
@amaneshi can you clarify where your frontend is?
In the best case scenario within the same server/Nginx instance:
- Nginx will proxy all requests to say
example.com/api
to Strapi (via that proxy block)
- Angular (depending if it’s SSR or CSR) would either be served as static assets (not from within Strapi but directly from nginx) or you would have another proxy block to connect to a live running instance of Angular SSR.
You shouldn’t serve both Strapi and Angular within the same node process (such as building the Angular application and putting the dist folder in the public folder).
I’m going to move this over to a discussion as it’s not really a bug with Strapi but a question about it’s usecase.
Author
To be clear - yes, I start strapi proccess on default port with reverse proxy in Nginx (in root location now, like example.com/ after proxy). My config (main pieces):
upstream strapi {
server ubuntu_strapi_1:1337; // My docker service
}
# HTTPS Server
server {
listen 443 http2 ssl;
server_name mydomain.com;
location /api/ {
proxy_pass http://strapi/;
// Other proxy headers...
}
}
And added “url” parameter to server config file
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'https://mydomain.com/api',
});
But you say this is not a bug, I partly disagree with you. Previously I user relative url and have this problem (as documentation say it can be either), but with absolute route with domain this configuration works.
So you can close this issue but or remove phrase about possible relative path or fix it.
Thank you for attention!
Collaborator
@petersg83 maybe I missed something related to using a relative URL here?
Author
When I used url like “/api” or “api” - some requests not worked as they should
Maintainer
Hi 
Maybe you want to look at the parameter admin.url:
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'https://mydomain.com/api',
admin: {
url: "https://mydomain.com/api/admin",
}
});