New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust rewrite logic on sample proxy configurations #156
Comments
I don't recommend using subfolder proxying. Your Strapi should be on it's own sub-domain like API.example.com Your front end also should not live in the public folder of Strapi and should have it's own virtual host config. |
What do you mean? My frontend lives in a separated container. |
tried with subdomain and still not working, more or less the same error
Everything loads correctly but when I try to navigate to |
Ok, after 2 days I have solved it 🙏 .
and then in your strapi config
|
fuck finally! thank you @MatteoGioioso |
@MatteoGioioso where did you change this? which file?:
|
@hzrcan that should be the |
@MatteoGioioso Tnx! But is a subfolder impossible? Still prefer that. |
@mb89 There is official documentation about it:
which involves both Nginx and Strapi configuration, but! I haven't succeeded yet to make it work. EDIT: |
@needleshaped Tnx, missed the tabs! I got /etc/nginx/sites-available/strapi.conf:
config/server.js:
|
Hi ! I am beginner in strapi, could you please explain a bit more ? What do you mean by Your front end also should not live in the public folder of Strapi and should have it's own virtual host config.? |
This issue is quite old and we offer some same configs for working with split frontend and backend here: https://strapi.io/documentation/v3.x/getting-started/deployment.html#optional-software-guides But to answer your question, Strapi is a Headless CMS, so it's designed to be ran on it's own without also trying to serve a frontend. Depending on your frontend, it's better to offload that to an actual web server (Nginx, Apache, Caddy, Traefik, ect). Some frontend frameworks can also run as a service (aka SSR or Server Side Rendering) and likewise should be proxied by Nginx. |
I dont know if that helps anyone. But it took me 6 hours until i found out to delete |
Alternative is to use the |
I know this is an old issue...but ouch! I can confirm this is still the case.
This means (option 1) if you are trying to manage your builds/deploys with a CI, you need to make your FULL production ENV (secrets included I suppose) available to the CI...because you don't know as a user which of the values in Or (option 2) you just use the CI to do what it can (e.g. The last (option 3) is manual deployment and giving users ssh access to production to manually manage/update strapi on production boxes. For security and data privacy reasons we try to strongly limit any SSH access to production machines and the access that is there is for "reading" (debugging) and users are not generally supposed to be making changes as there is a strong chance (if they even have access) their changes will conflict or be overwritten by our server management/provisioning code. So this option means that strapi servers cannot be handled in the same way as other production api and webservers...means losing out on a lot of automated monitoring, nginx stats, etc. The underlying problem here (well for us) is that config is hard-coded into the webpack build (maybe other things?) at the Another thing... apparently mounting strapi under an nginx location block with a prefix (e.g. Am I missing something here on strapi deployment/devops or is this project really not compatible with devops environments? It is okay if strapi is really designed for non-devops users who manually manage a small number of servers (e.g. the pm2 people)...even if that means it isn't really compatible with enterprise deployment environments and controls. Update
And we are just trying to avoid having strapi modifying state (db, uploads, etc) outside of known locations that we can manage backup/restore/migrate/etc. We are getting closer. Here is what we came up with for anyone else that has the same concerns or requirements... decoupling CI build from deployment and target serverThe webpack build needs to happen on the CI (for us) and needs to know its own base path as well as the path to get to the API. Strapi assumes that if your public admin url isn't absolute (starts with Our solution on this was to patch This allows us to avoid having to tell our CI or the Of course the target server that consumes/deploys the tarball needs to know about this convention and nginx needs to be setup to match. So there is some coupling between CI and production as not everything can be passed as runtime config (the build config). The strapi systemd service (passes env and runs This allows us to use the same tarball (domain-name independent) for both staging and production servers and not have to run After looking through the code the only ENV needed for moving uploads dir (
|
This is caused by how Koa-router looks for routes, it does regex matching and with a prefix you would have to manually update all of the prefixes for every model via the routes.json. We opted not to mess with the koa router to handling sub-folder based proxying |
Thanks for the clear explanation. A little feedback as a new to strapi (3 days) user reading docs to do an enterprise deployment. Just some things I think that are important requirements or warnings that could be called out better in the docs. Sorry if I missed them and they are there.
|
So the doc example (subfolder-unified) uses this rewrite in the
Anyone see an issue with small modification to make the trailing slash optional on original uri, but leading slash mandatory on re-written?
Unless I am missing something, the tweaked rewrite will result in the following which I can't imagine breaking anything in terms of strapi uri expectations. Not a big deal just nice not to have to worry about whether there is a trailing slash or not. Not sure if there is a meaningful performance penalty as I generally avoid doing rewrites if I can.
|
@mattpr no that makes perfect sense, can you open a PR on our documentation repo: https://github.com/strapi/documentation Please ignore the contribution guide and use the following PR branch for your base, as we are planning to merge it later this week and it's part of a massive restructure project: #154 |
I'm going to transfer this issue over to the docs repo and reopen it pending that suggestion for the configs. You may also want to check the HAProxy rewrite as well. |
Done. #157 |
Closing this issue fixed via pull request #157 Thank you for your contribution! |
is www required if using a subdomain?? |
No it's not |
See: #156 (comment)
Informations
What is the current behavior?
I am running
next.js
andstrapi.js
together on two separated docker containers withdocker-compose
.I want Nginx to redirect all the request from
www.mydomain.com/admin
to strapi admin page.This is my nginx config:
and my
server.json
Everything works fine and the app starts and works normally. However when I try to access the admin page of strapi I have the following error:
What is the expected behavior?
Admin page should load normally
Suggested solutions
The text was updated successfully, but these errors were encountered: