Skip to content

Instantly share code, notes, and snippets.

@Harry-Chen
Last active March 9, 2025 01:53
Show Gist options
  • Save Harry-Chen/032fef8b8ef0effd52b0cb6dd3fdf067 to your computer and use it in GitHub Desktop.
Save Harry-Chen/032fef8b8ef0effd52b0cb6dd3fdf067 to your computer and use it in GitHub Desktop.
NetBox Docker deployment under sub-directory

Assume your deployment is under /netbox:

Add to configuration/configuration.py

BASE_PATH = environ.get('BASE_PATH', '')

Add to env/netbox.env

BASE_PATH=/netbox

Then merge this with your own docker-compose.override.yml (or create one if not existed) to make health checker of Docker happy:

version: '3.4'
services:
  netbox:
    healthcheck:
      test: "curl -f http://localhost:8080/netbox/api/ || exit 1"

Outside NGINX config:

upstream netbox {
  server 127.0.0.1:8080; # or your own NetBox port
}

server {
  listen 80;
  
  location /netbox {
    proxy_pass http://netbox;
  }
  
  location /netbox/static {
    proxy_pass http://netbox/static/;
  }
}

The trick is to strip BASE_PATH on any requests to static resources.

@jose-hernandez2
Copy link

Hi,
I'm having the same issue with Netbox. In previous versions I was able to get a custom context root working by doing what I described here: netbox-community/netbox-docker#650 (comment) but that isnt' working anymore, as I now get constantly redirected to the homepage. Is it possible for you to share your whole nginx-unit.json file? The modifications you talk about here when you say "Outside NGINX config" were done in that file, right? If I try adding something like your example here, my NGINX fails to start, so I'm probably misunderstanding something.
Thanks in advance!

@Harry-Chen
Copy link
Author

Is it possible for you to share your whole nginx-unit.json file? The modifications you talk about here when you say "Outside NGINX config" were done in that file, right?

@jose-hernandez2 No, I did not touch nginx-unit.json. Instead I am running an NGINX outside of the containers and use the config in this snippet to forward static and dynamic resources accordingly.

@joseprrm
Copy link

Hi @jose-hernandez2 ,

I was also getting the redirection to the login page. It got solved after I deleted all the cookies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment