This repository contains a guide for building and running NetBox on Windows. It is a work in progress; please submit a bug report for any issues you encounter.
This documentation needs a lot of improvement and validation. Please don't use this unless you know what you're doing for now! It's highly experimental in multiple ways. It is intended to follow roughly the flow of the original NetBox documentation, and the tooling and software chosen is supposed to match the Linux way as closely as possible.
NOTE: This is currently unsupported! I'll still try to help if possible but understand that this is not being worked on actively.
Please also note that this is based on the latest version of python2 and has NOT been tested properly on python3. Use at your own risk!
Various reasons. I would like to eventually explore Bash on Windows and maybe port this to it, but Bash/Ubuntu on Windows is not available for Windows 7 and is thus not as flexible.
(Dev note: If you don't install libpq5, importing the psycopg2 module WILL NOT WORK with a really vague error)
Create a super user account.
# ./manage.py createsuperuser
Username: admin
Email address: zorlin@gmail.com
Password:
Password (again):
Superuser created successfully.`
# ./manage.py collectstatic --no-input
You have requested to collect static files at the destination
location as specified in your settings:
/opt/netbox/netbox/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Populate netbox with some initial example data. HIGHLY recommended.
# ./manage.py loaddata initial_data
Installed 43 object(s) from 4 fixture(s)
./manage.py runserver 0.0.0.0:8000 --insecure
Performing system checks...
System check identified no issues (0 silenced). June 09, 2017 - 08:54:45 Django version 1.11.2, using settings 'netbox.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
* Open your browser to http://localhost:8000/
## Congratulations!
If all has gone well so far, you should see NetBox! If not, make sure you have 'localhost' in ALLOWED_HOSTS.
Running NetBox in this setup is not really suitable for production use, however.
# Web Server
## Web Server Installation
We'll be using nginx, gunicorn and supervisord. You will want to replace "wings" with your Windows username throughout this section.
## nginx Installation
* Create the directory C:\nginx\
* Visit http://nginx.org/en/download.html and download the latest Mainline version of nginx for Windows.
* Extract it into C:\nginx (nginx.exe should be @ C:\nginx\nginx.exe)
* Open C:\nginx\conf\nginx.conf in your favourite editor.
* Replace the entire server {} block with the following:
server { listen 80;
server_name localhost;
client_max_body_size 25m;
location /static/ {
alias C:/netbox/current/netbox/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
* Save and exit the file
* We'll come back to nginx later.
## gunicorn Installation
* Install gunicorn
* pip2 install gunicorn
* Open C:\netbox\current\gunicorn_config.py in your favourite editor (note, it doesn't exist yet)
command = '/usr/bin/gunicorn' pythonpath = '/cygdrive/c/netbox/current/netbox' bind = '127.0.0.1:8001' workers = 4 user = 'wings'
Again, we'll come back to gunicorn later.
## supervisord Installation
* Install supervisord
* pip2 install supervisor
* Create conf and log directories
mkdir -p /etc/supervisor/conf.d mkdir -p /var/log/supervisor/
* Open /etc/supervisor/supervisord.conf with your favourite editor and fill it with the contents of this gist, then save...
* https://gist.github.com/Zorlin/4471e6609326390fc4d35c0502be1929
* TODO: clean this up a bit?
* Open /etc/supervisor/conf.d/netbox.conf with your favourite editor (also doesn't exist yet), fill it with this and save...
[program:netbox] command = gunicorn -c /cygdrive/c/netbox/current/gunicorn_config.py netbox.wsgi directory = /cygdrive/c/netbox/current/ user = wings
## Testing it all out
We're going to do a quick dry-run to make sure everything works.
* Boot up gunicorn via supervisord
* /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
* Visit localhost:8001 in your browser. If the page loads but has no styling, that's good, don't worry!
* Go to C:\nginx and open nginx.exe either in the command line or file explorer. It should pop up a black window that immediately closes.
* Visit localhost:80 in your browser. Everything should look perfect at this point. If so, congratulations!
If that worked, shut everything back off.
* Switch to the Cygwin64 Terminal and STOP supervisord by hitting CTRL-C.
* Kill any nginx processes that are running.
# Making it permanent - Services!
Time to make your installation a bit more permanent. This will allow you to manage Nginx and Supervisord as services, allowing them to start on boot and other nice stuff. We will install and run supervisord first, then add nginx.
## Install cygwin run service utility
Before we proceed, we'll need to add a utility to cygwin called cygrunsrv.
* In an administrator command prompt, go back to your Downloads folder
* Re-run the cygwin installer with this command
* setup-x86_64.exe -q -P cygrunsrv
## supervisord
* In an administrator command prompt, go to C:\cygwin64\bin
* Run this command to install supervisord as a service
* cygrunsrv --install supervisord --path /usr/bin/python --args "/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf"
* We now need to revisit our configuration as it changes at this point - services run under the SYSTEM user.
* Open /cygdrive/c/netbox/current/gunicorn_config.py and replace "wings" (or your user) with "SYSTEM".
* Open /etc/supervisor/conf.d/netbox.conf and replace "wings" (or your user) with SYSTEM."
* In an administrator command prompt, run NET START supervisord - hopefully the service will start successfully.
* Test the service-ified supervisord by visiting localhost:8001. You should see an unstyled version of NetBox, like you did earlier.
## nginx
(Adapted from https://stackoverflow.com/questions/10061191/add-nginx-exe-as-windows-system-service-like-apache)
* Grab the latest Windows Service Wrapper from GitHub - https://github.com/kohsuke/winsw/releases - you want one called WinSW.NET4.exe
* Drag that into your C:\nginx directory and then rename it to nginxservice.exe
* With your favourite editor, open C:\nginx\nginxservice.xml. Fill it with this and save...
* Finally, as an administrator, CD to c:\nginx and run "nginxservice.exe install"
* Run "net start nginx"
Now visit localhost:80 and check that everything works. If it does, congratulations! You have a full NetBox install running on Windows.
(This should still be considered experimental. For example, nginx on Windows is only in beta! Still, enjoy.)
Hopefully your browser now looks like this :)
![A demo of NetBox on Windows in production mode](http://i.imgur.com/cGk0Xyb.png)