nginx "502 Bad Gateway" error

8,296 views
Skip to first unread message

Terry McKenna

unread,
Oct 27, 2016, 7:23:46 PM10/27/16
to NetBox
Hi Guys,

I followed all of the instructions in the install doc and am able to start the dev http server: # ./manage.py runserver 0.0.0.0:800
The page does display, albeit not correctly, so I tried setting up the 'nginx' http server and all I get is a "502 Bad Gateway" message.

Anyone have any ideas why?

The only thing that I would consider different than what the docs call out is that it's a Ubuntu VM and not a member of a domain:

server { listen 80; server_name Ubuntu-16; 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"'; } }


configuration.py
ALLOWED_HOSTS = ['Ubuntu-16','192.168.1.14'']


Thanks

Josh VanDeraa

unread,
Oct 28, 2016, 9:09:10 AM10/28/16
to NetBox
I'm new to Netbox myself, and I'm having some troubles with Ubuntu 16.04 and Apache web service myself when I ran across this article:

https://github.com/digitalocean/netbox/issues/137

Seems to be relatively related.

Jeremy Stretch

unread,
Oct 28, 2016, 10:31:22 AM10/28/16
to Josh VanDeraa, NetBox
A 502 error indicates that the WSGI service behind nginx is not running. Double-check that your gunicorn config matches the documentation and restart the supervisor service.

If it still doesn't work, try executing gunciorn manually and see what errors it reports (adjust the commands below as necessary to match your installation):

cd /opt/netbox/netbox/
sudo -u www-data gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi


Jeremy

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/f09dcc9b-8959-4a4e-951a-66a147f7ebcc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Terry McKenna

unread,
Oct 28, 2016, 1:11:31 PM10/28/16
to NetBox
Thanks Jeremy, I'll check it out.

I want to mention a discrepancy between what I am seeing installing on Ubuntu 16.04.01 and the documentation:
States:
Configuration

Move into the NetBox configuration directory and make a copy of configuration.example.py named  configuration.py.

# cd netbox/netbox/

I cut-&-paste all the commands from the install guide so this can be verified by doing the same, the "configuration.example.py" file is located at:
/opt/netbox/netbox/netbox and not at /opt/netbox/netbox

Is that an issue? I performed this install twice and it's the same both times.

Thanks

Terry McKenna

unread,
Oct 30, 2016, 12:25:04 PM10/30/16
to NetBox
I see what I did wrong here. The previous step is run from /opt/netbox so the instructions to "cd /netbox/netbox/" are correct.

--
You received this message because you are subscribed to a topic in the Google Groups "NetBox" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/netbox-discuss/rTF_Mcha1Vs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to netbox-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to netbox-discuss@googlegroups.com.

Terry McKenna

unread,
Nov 29, 2016, 3:07:16 PM11/29/16
to NetBox
So here's how I messed up...

I skipped the entire section in the documentation for installing and configuring both gunicorn and supervisord. I thought those were part of the Apache install. Once I followed the documentation the nginx server works.

One problem, I have to manually run $cd /opt/netbox/netbox/; $sudo -u www-data gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi after booting the server. Is that expected? 

Thanks

On Thursday, October 27, 2016 at 7:23:46 PM UTC-4, Terry McKenna wrote:

Ravi Bhikhie

unread,
May 8, 2017, 7:15:32 AM5/8/17
to NetBox
Apologies for kicking up an old topic, but I ran into this last night as well.

The documentation does say to install and set up Gunicorn and Supervisor HOWEVER, it doesn't really describe why.
So that's my question: what do both applications do and why does Nginx throw an error 502 when they are not running?

I thought it was possible to set up a website just using Nginx itself?
I'm trying to understand more about how Netbox operates.

Thanks!

bellwood

unread,
May 8, 2017, 1:57:35 PM5/8/17
to NetBox
Gunicorn is the WSGI server (it serves the actual Django WSGI)

Supervisor daemonizes gunicorn.

NGINX sits in front, serves the static content and proxies application traffic to and from gunicorn.

Ravi Bhikhie

unread,
May 9, 2017, 4:30:02 AM5/9/17
to NetBox
Thanks!

Sean Scarfo

unread,
Feb 20, 2018, 7:16:28 AM2/20/18
to NetBox
Did you ever get this working?  I too am having problems?

Dustin Peet

unread,
Jun 14, 2019, 12:51:46 PM6/14/19
to NetBox
Just wanted to post something that helped me regarding this issue quickly... 

I was getting 502 errors until I made my gunicorn_config file executable.  Makes sense, but the document doesn't seem to detail that specifically

For me (Ubuntu 18.04.2):

sudo chmod 755 /opt/netbox/netbox/gunicorn_config.py

then I kicked the supervisor and nginx services and FINALLY got the web page to load.  Such a feeling of accomplishment (and relief) :)

HTH
Reply all
Reply to author
Forward
0 new messages