path strangeness when running under mod_wsgi #891

Closed
opened 2025-12-29 16:26:45 +01:00 by adam · 2 comments
Owner

Originally created by @Svedrin on GitHub (Apr 27, 2017).

I've configured netbox to run under Apache 2.4 and Python 3 with mod_wsgi ("apt-get install libapache2-mod-wsgi-py3"). Netbox is running under the "/netbox" path, but I couldn't seem to get that configured correctly. If I set BASE_PATH = "netbox/" in configuration.py, netbox displays the static content correctly, but seems to think it's running under /netbox/netbox: I only get an HTTP 404 error. If I go to /netbox/netbox/admin, the admin page displays - but it should instead appear under /netbox/admin/.

Vice versa, if I set BASE_PATH = "", all the paths are correct (so, the admin appears under /netbox/admin/ like it should), but links to static content are missing the /netbox/ part. Hence static content is missing.

I "fixed" that by hardcoding STATIC_URL = "/netbox/static/" in settings.py, but that's not an ideal solution.

Here's my apache config:

<VirtualHost *:80>
    Alias /netbox/static /opt/netbox/netbox/static

    <Directory /opt/netbox/netbox/static>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Require all granted
    </Directory>

    <Directory /opt/netbox/>
        Require all granted
    </Directory>

    WSGIScriptAlias         /netbox /opt/netbox/netbox/netbox/wsgi.py
    WSGIDaemonProcess       netbox processes=25 threads=1 user=www-data group=www-data
    WSGIProcessGroup        netbox
    WSGIScriptReloading     Off
    WSGIPassAuthorization   On
</VirtualHost>

And I had to add these lines to netbox/wsgi.py:

import sys
sys.path.insert(0, "/opt/netbox/netbox")
Originally created by @Svedrin on GitHub (Apr 27, 2017). I've configured netbox to run under Apache 2.4 and Python 3 with mod_wsgi ("apt-get install libapache2-mod-wsgi-py3"). Netbox is running under the "/netbox" path, but I couldn't seem to get that configured correctly. If I set `BASE_PATH = "netbox/"` in `configuration.py`, netbox displays the static content correctly, but seems to think it's running under `/netbox/netbox`: I only get an HTTP 404 error. If I go to `/netbox/netbox/admin`, the admin page displays - but it should instead appear under `/netbox/admin/`. Vice versa, if I set `BASE_PATH = ""`, all the paths are correct (so, the admin appears under `/netbox/admin/` like it should), but links to static content are missing the `/netbox/` part. Hence static content is missing. I "fixed" that by hardcoding `STATIC_URL = "/netbox/static/"` in settings.py, but that's not an ideal solution. Here's my apache config: ``` <VirtualHost *:80> Alias /netbox/static /opt/netbox/netbox/static <Directory /opt/netbox/netbox/static> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted </Directory> <Directory /opt/netbox/> Require all granted </Directory> WSGIScriptAlias /netbox /opt/netbox/netbox/netbox/wsgi.py WSGIDaemonProcess netbox processes=25 threads=1 user=www-data group=www-data WSGIProcessGroup netbox WSGIScriptReloading Off WSGIPassAuthorization On </VirtualHost> ``` And I had to add these lines to `netbox/wsgi.py`: ``` import sys sys.path.insert(0, "/opt/netbox/netbox") ```
adam closed this issue 2025-12-29 16:26:45 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 27, 2017):

GitHub issues are intended for reporting bugs and requesting features. For general discussion or assistance with installation issues, please post to our mailing list.

@jeremystretch commented on GitHub (Apr 27, 2017): GitHub issues are intended for reporting bugs and requesting features. For general discussion or assistance with installation issues, please post to our [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss).
Author
Owner

@kartiksubbarao commented on GitHub (Mar 22, 2019):

I found this note as helpful background in setting up netbox with mod_wsgi. In my searching, I also found that you can specify the python-path argument to the WSGIDaemonProcess directive (instead of having to modify netbox/wsgi.py):

WSGIDaemonProcess netbox python-path=/opt/netbox/netbox

@kartiksubbarao commented on GitHub (Mar 22, 2019): I found this note as helpful background in setting up netbox with mod_wsgi. In my searching, I also found that you can specify the python-path argument to the WSGIDaemonProcess directive (instead of having to modify netbox/wsgi.py): ```WSGIDaemonProcess netbox python-path=/opt/netbox/netbox```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#891