You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
User InterfaceRelated to the frontend / User InterfaceenhancementThis is an suggested enhancement or new featureroadmapThis is a roadmap feature with no immediate plans for implementation
Currently the only supported way to host inventree project is domain root. http://inventree.com/
It would be more flexible if one could host it on subdir too, e.g. http://example.com/inventree
I thought that changing STATIC_URL and MEDIA_URL will be enough, but it seems that / prefix is used in a lot of scripts and templates including redirect to /index in urls.py
Reacted by fenugrec, marklinmax, Drew Hubley, Dylan Starink, Oliver Lippert and Seth M. Price
Sure I can help with testing.
I tried to deploy inventree on my server using Apache + mod_wsgi.
I implemented 'url_prefix' config parameter (almost as you did in #1298) url_prefix: '/inventree' in config.yaml
and in settings.py URL_PREFIX = CONFIG.get('url_prefix','') STATIC_URL = URL_PREFIX+'/static/' MEDIA_URL = URL_PREFIX+'/media/'
And I changed all /part to part in InvenTree/templates/js/part.js just to check it is working.
I guess there are a lot of places where links should be changed to relative to work properly with subdirs.
Besides that, I had errors in inventreeCommitHash() and inventreeCommitDate() from version.py because git command was executed in root / directory.
I fixed it using cwd param: return str(subprocess.check_output('git rev-parse --short HEAD'.split(),cwd=os.path.dirname(os.path.realpath(__file__))), 'utf-8').strip()
@SchrodingersGat a transparent rewrite /proxy seems like a good idea. But I would leave that to the admin of the webserver, that works with the current setup relatively easy.
@matmair do you have some more details on this? I'd like to know that it can be made to work well by (for e.g.) nginx, so that I can close out this issue. I'd rather not have InvenTree handle this problem.
I tried to implement the url rewrite as per the suggestion of @rcludwick above.
It worked somewhat - a request for localhost:8000/subdir/part/ correctly sent me to /part/ InvenTree view.
However, the InvenTree page then requested static files from /static/ which the proxy tried to serve from localhost:8000/static/ and this then failed.
Yeah, it's been a while though. I'd have to do a little research. I'm
vastly more familiar using traefik as a reverse proxy than nginx lately.
Basically you set up nginx to route by path or by hostname.
I have a host named 'i' that routes to the same up address and port, but is
routed inside traefik to inventree.
You should also be able to route my.domain/inventree/* to rewrite the url
to remove the root path.
Sorry to jump in like that, but isn't nginx proxy_pass and url rewrite one-way? The server will effectively receive the request without the subpath, but will not redirect well since it isn't aware of the modification.
I tried configuring it like that and could reach the server but never got a proper response.
Maybe I am just doing something wrong?
So I think that both the INVENTREE_SUBPATH environment variable and nginx proxy_pass / url rewrite are needed.
On Fri, Jul 2, 2021, 12:34 PM marklinmax ***@***.***> wrote:
Sorry to jump in like that, but isn't nginx proxy_pass and url rewrite
one-way? The server will effectively receive the request without the
subpath, but will not redirect well since it isn't aware of the
modification.
I tried configuring it like that and could reach the server but never got
a proper response.
Maybe I am just doing something wrong?
So I think that both the INVENTREE_SUBPATH environment variable and nginx
proxy_pass / url rewrite are needed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1297 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL67I3R7FNIQICEWFJU4ADTVYBELANCNFSM4XSJG5HA>
.
I have never been able to get URL rewriting to work. I don't believe URL rewriting would be the correct way to handle this, especially if Django has some provision for this feature.
The main reason for this in my case is I need only run a small instance of Inventree that is available publicly for my personal use but it doesn't need to be advertised. While security-by-obscurity is not secure by itself, it doesn't hurt as an additional independent layer of security. Mostly, not having my instance publicly indexed adds another hurdle for a malicious botnet to overcome.
Other advantages to using subdir URLs are reduced administration of the DNS records for subdomains and reduced management of SSL certificates.
An alternative might be a wildcard DNS record, though I haven't explored this concept.
what you are trying to achieve is not really helped by this sub-path approach, it is very much a false sense of layer of security. also if you are doing manual ssl management you should look into ACME / LEGO
I've been running two InvenTree instances under different subdomains. I'll describe it here, in case it helps anyone.
I've set up the DNS settings with my domain registrar to forward the inventree-test.example.com and inventree.example.com subdomains to my Inventree server (Debian VM), while the TLD example.com still sends people to my main (not inventree) web server.
There's a high level directory with a Caddy server running in Docker, as a pretty minimal/simple reverse proxy. This forwards incoming HTTPS requests to the relevant instance.
Each InvenTree instance is a separate Docker container but both are running on the same cloud-hosted Debian VM.
The two InvenTree instances are stored in sub-directories and brought up as a set of docker containers named "inventree_" based on environment variables set in .env (so that their internal Caddyfiles are identical). In my case these are inventree_test (test server) and inventree_prod (production server).
I am by no means an expert and it took me a while to work this out. I have no idea if it's the best approach, but it works well for me. I'm happy to share more details or help others if I can.
If anyone else ends up using it... @matmair, @SchrodingersGat, tell me if you want me to write it up somewhere less ephemeral.
User InterfaceRelated to the frontend / User InterfaceenhancementThis is an suggested enhancement or new featureroadmapThis is a roadmap feature with no immediate plans for implementation
Activity
SchrodingersGat commentedon Feb 14, 2021
Huh, I never considered this. But yeah, that's a problem!
I'm going to start a branch with support for this. Can you help me out with testing?
For now, can you please let me know where you are coming across errors due to links not working properly?
Thanks
SchrodingersGat commentedon Feb 14, 2021
Oh and also the changes that you initially made to
STATIC_URLandMEDIA_URLsintech commentedon Feb 14, 2021
Sure I can help with testing.
I tried to deploy inventree on my server using Apache + mod_wsgi.
I implemented 'url_prefix' config parameter (almost as you did in #1298)
url_prefix: '/inventree'in config.yamland in settings.py
URL_PREFIX = CONFIG.get('url_prefix','')STATIC_URL = URL_PREFIX+'/static/'MEDIA_URL = URL_PREFIX+'/media/'And I changed all
/parttopartinInvenTree/templates/js/part.jsjust to check it is working.I guess there are a lot of places where links should be changed to relative to work properly with subdirs.
Besides that, I had errors in
inventreeCommitHash()andinventreeCommitDate()fromversion.pybecausegitcommand was executed in root/directory.I fixed it using
cwdparam:return str(subprocess.check_output('git rev-parse --short HEAD'.split(),cwd=os.path.dirname(os.path.realpath(__file__))), 'utf-8').strip()SchrodingersGat commentedon Feb 17, 2021
@sintech could you please check the branch in #1298 and see what still needs work?
sintech commentedon Feb 17, 2021
SchrodingersGat:subdir-serverand deployed it using separate mysql DB.subpath: '/inventree'to config.yamlrequest.path_infohas/loginwhilereverse_lazy('login')has/inventree/loginat https://github.com/SchrodingersGat/InvenTree/blob/bf0e92ea36298c70845fb9269f41d8716c1334d3/InvenTree/InvenTree/middleware.py#L78request.path_infotorequest.pathjust for testos.path.join(SUBPATH_URL, STATIC_URL)did not join becauseSTATIC_URL = '/static/'configured as absolute path at https://github.com/SchrodingersGat/InvenTree/blob/bf0e92ea36298c70845fb9269f41d8716c1334d3/InvenTree/InvenTree/settings.py#L149*_URLto relative pathdomain.com/index/url='/index/'tourl='index/'at https://github.com/SchrodingersGat/InvenTree/blob/bf0e92ea36298c70845fb9269f41d8716c1334d3/InvenTree/InvenTree/urls.py#L170domain.com/index/domain.com/part/1/instead ofdomain.com/inventree/part/1/So partially it works but some links are still wrong.
My server configuration (apache 2.4 + mod_wsgi):
SchrodingersGat commentedon Mar 10, 2021
@sintech can you please post your settings.py file after your modifications?
sintech commentedon Mar 10, 2021
Sure, here is diff:
rcludwick commentedon Jun 15, 2021
Apologies for coming in late. Doesn't nginx/apache support transparently rewriting of urls in the reverse proxy mode?
https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite
That would probably be the proper way to handle this.
SchrodingersGat commentedon Jun 16, 2021
@rcludwick I would like to push this problem outside of the scope of the InvenTree server itself.
I just tried configuring a nginx setup as per your example but could not get it to work. Have you had specific experience with this?
matmair commentedon Jun 16, 2021
@SchrodingersGat a transparent rewrite /proxy seems like a good idea. But I would leave that to the admin of the webserver, that works with the current setup relatively easy.
SchrodingersGat commentedon Jun 16, 2021
@matmair do you have some more details on this? I'd like to know that it can be made to work well by (for e.g.) nginx, so that I can close out this issue. I'd rather not have InvenTree handle this problem.
I tried to implement the url rewrite as per the suggestion of @rcludwick above.
It worked somewhat - a request for
localhost:8000/subdir/part/correctly sent me to/part/InvenTree view.However, the InvenTree page then requested static files from
/static/which the proxy tried to serve fromlocalhost:8000/static/and this then failed.rcludwick commentedon Jun 17, 2021
rcludwick commentedon Jun 20, 2021
Apologies for taking a while.
proxy_passon nginx is the way to go here. It rewrites the url before handing it off.https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
Apache might do it too, but it's been around 2 decades since I last touched apache. mod_rewrite maybe? I don't know.
I would close this and add documentation on at least for nginx.
marklinmax commentedon Jul 2, 2021
Sorry to jump in like that, but isn't nginx proxy_pass and url rewrite one-way? The server will effectively receive the request without the subpath, but will not redirect well since it isn't aware of the modification.
I tried configuring it like that and could reach the server but never got a proper response.
Maybe I am just doing something wrong?
So I think that both the INVENTREE_SUBPATH environment variable and nginx proxy_pass / url rewrite are needed.
rcludwick commentedon Jul 2, 2021
53 remaining items
SchrodingersGat commentedon Nov 12, 2024
So, are you suggesting we should bump to a later release e.g.
1.1.0? I am OK with thatwolfpackmars2 commentedon Sep 3, 2025
I'm glad to see there is a lot of discussion about this topic. I too would like to see this feature.
Django has a setting "FORCE_SCRIPT_NAME". However, it needs to be supported by the app.
An example django app that uses this is Paperless-ngx, implemented via settings.py. For funsies, I tried setting INVENTREE_FORCE_SCRIPT_NAME in .env, but no dice as expected. See also https://docs.paperless-ngx.com/configuration/#PAPERLESS_FORCE_SCRIPT_NAME
I have never been able to get URL rewriting to work. I don't believe URL rewriting would be the correct way to handle this, especially if Django has some provision for this feature.
The main reason for this in my case is I need only run a small instance of Inventree that is available publicly for my personal use but it doesn't need to be advertised. While security-by-obscurity is not secure by itself, it doesn't hurt as an additional independent layer of security. Mostly, not having my instance publicly indexed adds another hurdle for a malicious botnet to overcome.
Other advantages to using subdir URLs are reduced administration of the DNS records for subdomains and reduced management of SSL certificates.
An alternative might be a wildcard DNS record, though I haven't explored this concept.
matmair commentedon Sep 3, 2025
what you are trying to achieve is not really helped by this sub-path approach, it is very much a false sense of layer of security. also if you are doing manual ssl management you should look into ACME / LEGO
newfolder0 commentedon Mar 10, 2026
I've been running two InvenTree instances under different subdomains. I'll describe it here, in case it helps anyone.
I am by no means an expert and it took me a while to work this out. I have no idea if it's the best approach, but it works well for me. I'm happy to share more details or help others if I can.
If anyone else ends up using it... @matmair, @SchrodingersGat, tell me if you want me to write it up somewhere less ephemeral.
matmair commentedon Mar 10, 2026
The question is about subdirectory hosting, not subdomain hosting as you are doing (which is fully supported)
newfolder0 commentedon Mar 10, 2026
Aaah sorry, my mistake.
Oinosseus commentedon Aug 14, 2026
Hello, I also have the issue that I want to operate InvenTree with a sub-path like https://my.server.tld/inventree
My setup is an apache with reverse proxy. I have no knowledge about django/gunicorn and could not make it accept the sub-path. Also I had no luck with url/path replacing in the apache config.
Are there meanwhile any recommendations how to operate InvenTree with sub-path in the URL?
matmair commentedon Aug 14, 2026
That is not supported and will cause numerous hard to debug issues