skip to Main Content

Hello and thanks for taking time to read this request for help.

I am installing a web application called Netbox, which is built on Django. A basic Gunicorn is front-ended with NGINX in a rather simplie configuration.

The problem I’m running into is that the web application reports that it is unable to load any of the static files, and I can validate that I’m getting a 404 for these requests.

I have validated that I can view the correct files in the /static/ path referenced in the NGINX path /opt/netbox/netbox/static, and the permissions are correctly set as well.

Since this is a Django web app, I have performed a simple test with the built-in test web server and all the static files are correctly rendered; this is almost certainly an issue between Gunicorn and my NGINX configuration.

nginx.conf

server {
    listen 443 ssl;

    # CHANGE THIS TO YOUR SERVER'S NAME
    server_name netbox.example.com;

    ssl_certificate /etc/ssl/certs/netbox.crt;
    ssl_certificate_key /etc/ssl/private/netbox.key;

    client_max_body_size 25m;

    location /static/ {
        alias /opt/netbox/netbox/static/;
    }

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

server {
    # Redirect HTTP traffic to HTTPS
    listen 80;
    server_name _;
    return 301 https://$host$request_uri;
}

gunicorn.py

bind = '127.0.0.1:8001'
workers = 5
threads = 3
timeout = 120
max_requests = 5000
max_requests_jitter = 500

error message when browsing http://localhost:8001/

I have received the same results on the following setups:

  • Ubuntu 18.04 (Azure)
  • Ubuntu 19.10 (local VM)
  • Ubuntu 20.04 (local VM)
  • Centos 8.1 (Azure)
  • same error when using the Apache alternative setup method

I would appreciate any ideas on where I can go to validate things like permissions or check into logs.

2

Answers


  1. Try using root instead of alias. Nginx documentation recommends to use root when location matches the last part of the directive’s value. I think is to avoid duplication of the $uri, /static in your example, when using alias.

    So try this:

        location /static/ {
            root /opt/netbox/netbox;
        }
    
    Login or Signup to reply.
  2. Deriving from the answer by @mgsxman, you can also set it as

    user root;
    

    config in the nginx.conf file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search