Netbox 2.3.3. + Centos 7.4 Fresh Install - 502 Bad Gateway

1,501 views
Skip to first unread message

Ollie

unread,
Jun 7, 2018, 6:27:08 PM6/7/18
to NetBox
Hi everyone, sorry for this post, it seems common enough but I have looked and the answers are varied and don't seem to match my install.

It a fresh Centos 7.4, I have followed the install guide. And then found the missing parts for the nginx config + others here:


I can run the dev model, from the guide like this: "python3 manage.py runserver 0.0.0.0:8000 --insecure"  this part works fine, no problems.

But yeah I am still stuck @ a '502 Bad Gateway' and am really not sure where to start troubleshooting. SElinux is disabled. HTTP, HTTPS + 8000/tcp allowed.

I don't think unicorn is running:

ps aux | grep gunicorn
root      2537  0.0  0.0 112704   972 pts/0    R+   18:05   0:00 grep --color=auto gunicorn




/etc/supervisord.d/netbox.conf 

[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = nginx


       

/opt/netbox/gunicorn_config.py

command = '/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
workers = 3
user = 'nginx'




/etc/nginx/conf.d/netbox.conf

server {
    listen 80;

    server_name ntbx01v-bj.example.com;

    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 $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"';
    }
}                                                                                                          



sudo -u nginx gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
[2018-06-07 18:16:38 -0400] [2623] [INFO] Starting gunicorn 19.8.1
[2018-06-07 18:16:38 -0400] [2623] [INFO] Listening at: http://127.0.0.1:8001 (2623)
[2018-06-07 18:16:38 -0400] [2623] [INFO] Using worker: sync
[2018-06-07 18:16:38 -0400] [2626] [INFO] Booting worker with pid: 2626
[2018-06-07 18:16:38 -0400] [2627] [INFO] Booting worker with pid: 2627
[2018-06-07 18:16:38 -0400] [2628] [INFO] Booting worker with pid: 2628

This seems to stop here and not get any further and results in a 'Bad Request (400)'.
CTRL+C -> Back to a 502 Bad Gateway.



tail -f /var/log/nginx/error.log
2018/06/07 18:23:45 [error] 2666#0: *8 connect() failed (111: Connection refused) while connecting to upstream, client: 10.x.x.x, server: ntbx01.mycompany.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "ntbx01.mycompany.com"


I hope there is enough info there to point out something obvious?? Would really appreciate it, thank you so much!!
Ollie

ryan guillory

unread,
Jun 7, 2018, 6:36:04 PM6/7/18
to NetBox
Hey, 

What do you get from the following commands: 

netstat -plutn

cd /etc/nginx/sites-enabled; ls -alt

Initially, when I had originally set up my VM there was a broken symbolic link and my IP was not bound to any portt. 

It's worth taking a look at. 
Message has been deleted
Message has been deleted

Ollie

unread,
Jun 7, 2018, 7:17:12 PM6/7/18
to NetBox
Reposting, not sure why it was deleted - How do they look?

netstat -plutn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2665/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      12149/sshd          
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      1087/postmaster     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1294/master         
tcp6       0      0 :::22                   :::*                    LISTEN      12149/sshd          
tcp6       0      0 ::1:5432                :::*                    LISTEN      1087/postmaster     
tcp6       0      0 ::1:25                  :::*                    LISTEN      1294/master         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           12475/chronyd       
udp6       0      0 ::1:323                 :::*                                12475/chronyd       


# cd /etc/nginx/conf.d/
# ls -alt
total 8
drwxr-xr-x. 2 root root   25 Jun  7 18:23 .
-rw-r--r--  1 root root  471 Jun  7 18:23 netbox.conf
drwxr-xr-x. 5 root root 4096 Jun  7 05:07 ..

ryan guillory

unread,
Jun 7, 2018, 9:46:35 PM6/7/18
to NetBox
Looks like you dropped into conf.d, run the ls -alt in the sites-enables directory; if the link is in red then it’s broken if it is blue then you are in good shape.

In regards to your port bindings I’m not seeing anything bound to port 8001. I fixed the by actually going into my gunicorn_conf.py file and changing the up to a quad zero 0.0.0.0 and that fixed it for me.

ryan guillory

unread,
Jun 7, 2018, 9:54:39 PM6/7/18
to NetBox
Also another thing to double check is to run which gunicor to find the file path for the executable command that’s located in the file you create during setup

Ollie

unread,
Jun 7, 2018, 11:25:59 PM6/7/18
to NetBox
I followed these steps for nginx on Centos7, slightly different but I'm pretty sure it achieves the same thing, and this way no link is used. Happy to be told this is indeed my problem though, don't get me wrong. https://github.com/digitalocean/netbox/issues/1906

Hmm adjust the gunicorn_config.py to have 0.0.0.0 also tried 0.0.0.0:8001, neither of these resulted in a anything bound to 8001.

That's the part that makes me think gunicorn  isn't running?

Ollie

unread,
Jun 7, 2018, 11:51:50 PM6/7/18
to NetBox
Actually, you kinda win, after setting 0.0.0.0:8001 in gunicorn_config.py, as you suggested, and then running the below it actually works and I can browse to it at hostname.domain.com

sudo -u nginx gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi

So if it works via that cmd - I'm guessing I am 95% there. How do I make it run without the cmd then?

sudo -u nginx gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
[2018-06-07 23:34:02 -0400] [10402] [INFO] Starting gunicorn 19.8.1
[2018-06-07 23:34:02 -0400] [10402] [INFO] Listening at: http://0.0.0.0:8001 (10402)
[2018-06-07 23:34:02 -0400] [10402] [INFO] Using worker: sync
[2018-06-07 23:34:02 -0400] [10405] [INFO] Booting worker with pid: 10405
[2018-06-07 23:34:02 -0400] [10406] [INFO] Booting worker with pid: 10406
[2018-06-07 23:34:02 -0400] [10408] [INFO] Booting worker with pid: 10408

Cheers!!

Ollie

unread,
Jun 8, 2018, 1:17:54 AM6/8/18
to NetBox
After digging into supervisorctl the last part was using .ini not .conf as the config file extension.

Then doing a reread prompted, and it was breadcrumbs after that.

supervisor> reread 
netbox: available
supervisor> add netbox
netbox: added process group
supervisor> status
netbox                           RUNNING   pid 1522, uptime 0:07:48

Server reboot and netbox is still up and running.

Just a few little steps that IF they were included in the install guide would really save some people some time.
Thanks for all the help!

ryan guillory

unread,
Jun 8, 2018, 2:30:33 AM6/8/18
to NetBox
Glad things worked out for you. I share the same sentiments, I spent a lot of time debiugging things that should not have been issues.

Jeremy Stretch

unread,
Jun 8, 2018, 9:28:02 AM6/8/18
to ryan guillory, NetBox
Please open an issue if you believe the documentation needs to be improved. Be sure to include the exact modifications you propose.

Jeremy

On Fri, Jun 8, 2018 at 2:30 AM, ryan guillory <rguil...@gmail.com> wrote:
Glad things worked out for you. I share the same sentiments, I spent a lot of time debiugging things that should not have been issues.

--
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/dbe8243f-2662-4fa3-b590-67b8157d3dbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages