1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

135 lines
4.7 KiB
Markdown
Raw Normal View History

2016-07-08 16:00:53 -04:00
# Web Server Installation
We'll set up a simple WSGI front end using [gunicorn](http://gunicorn.org/) for the purposes of this guide. For web servers, we provide example configurations for both [nginx](https://www.nginx.com/resources/wiki/) and [Apache](http://httpd.apache.org/docs/2.4). (You are of course free to use whichever combination of HTTP and WSGI services you'd like.) We'll also use [supervisord](http://supervisord.org/) to enable service persistence.
2016-07-08 16:00:53 -04:00
2016-09-26 14:21:10 -04:00
!!! info
Only Debian/Ubuntu instructions are provided here, but the installation process for CentOS/RHEL does not differ much. Please consult the documentation for those distributions for details.
```no-highlight
2016-09-26 14:21:10 -04:00
# apt-get install -y gunicorn supervisor
```
2016-07-08 16:00:53 -04:00
## Option A: nginx
The following will serve as a minimal nginx configuration. Be sure to modify your server name and installation path appropriately.
```no-highlight
2016-09-26 14:21:10 -04:00
# apt-get install -y nginx
```
2016-07-08 16:00:53 -04:00
2016-09-26 14:21:10 -04:00
Once nginx is installed, save the following configuration to `/etc/nginx/sites-available/netbox`. Be sure to replace `netbox.example.com` with the domain name or IP address of your installation. (This should match the value configured for `ALLOWED_HOSTS` in `configuration.py`.)
2016-07-08 16:00:53 -04:00
2016-11-30 12:01:45 -05:00
```nginx
2016-07-08 16:00:53 -04:00
server {
listen 80;
server_name netbox.example.com;
access_log off;
location /static/ {
alias /opt/netbox/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"';
}
}
```
2016-09-26 14:21:10 -04:00
Then, delete `/etc/nginx/sites-enabled/default` and create a symlink in the `sites-enabled` directory to the configuration file you just created.
2016-07-08 16:00:53 -04:00
```no-highlight
2016-07-08 16:00:53 -04:00
# cd /etc/nginx/sites-enabled/
# rm default
# ln -s /etc/nginx/sites-available/netbox
2016-07-08 16:00:53 -04:00
```
Restart the nginx service to use the new configuration.
```no-highlight
2016-07-08 16:00:53 -04:00
# service nginx restart
```
To enable SSL, consider this guide on [securing nginx with Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04).
## Option B: Apache
```no-highlight
2016-09-26 14:21:10 -04:00
# apt-get install -y apache2
```
2016-07-08 16:00:53 -04:00
Once Apache is installed, proceed with the following configuration (Be sure to modify the `ServerName` appropriately):
2016-11-30 12:01:45 -05:00
```apache
2016-07-08 16:00:53 -04:00
<VirtualHost *:80>
ProxyPreserveHost On
ServerName netbox.example.com
Alias /static /opt/netbox/netbox/static
<Directory /opt/netbox/netbox/static>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
<Location /static>
ProxyPass !
</Location>
ProxyPass / http://127.0.0.1:8001/
ProxyPassReverse / http://127.0.0.1:8001/
</VirtualHost>
```
Save the contents of the above example in `/etc/apache2/sites-available/netbox.conf`, enable the `proxy` and `proxy_http` modules, and reload Apache:
```no-highlight
2016-07-08 16:00:53 -04:00
# a2enmod proxy
# a2enmod proxy_http
# a2ensite netbox
# service apache2 restart
```
To enable SSL, consider this guide on [securing Apache with Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-14-04).
# gunicorn Installation
2016-09-26 14:21:10 -04:00
Save the following configuration file in the root netbox installation path (in this example, `/opt/netbox/`) as `gunicorn_config.py`. Be sure to verify the location of the gunicorn executable (e.g. `which gunicorn`) and to update the `pythonpath` variable if needed. If using CentOS/RHEL change the username from `www-data` to `nginx` or `apache`.
2016-07-08 16:00:53 -04:00
```no-highlight
2016-07-08 16:00:53 -04:00
command = '/usr/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = '127.0.0.1:8001'
workers = 3
user = 'www-data'
```
# supervisord Installation
Save the following as `/etc/supervisor/conf.d/netbox.conf`. Update the `command` and `directory` paths as needed.
```no-highlight
2016-07-08 16:00:53 -04:00
[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = www-data
```
2016-09-26 14:21:10 -04:00
Then, restart the supervisor service to detect and run the gunicorn service:
2016-07-08 16:00:53 -04:00
```no-highlight
2016-07-08 16:00:53 -04:00
# service supervisor restart
```
At this point, you should be able to connect to the nginx HTTP service at the server name or IP address you provided. If you are unable to connect, check that the nginx service is running and properly configured. If you receive a 502 (bad gateway) error, this indicates that gunicorn is misconfigured or not running.
!!! info
Please keep in mind that the configurations provided here are bare minimums required to get NetBox up and running. You will almost certainly want to make some changes to better suit your production environment.