Enabled HTTPS and for nginx and then it shows 502 bad gateway

July 2, 2018 3.4k views
Nginx Ubuntu 16.04

I have installed NGINX on my ubuntu 16.04 VPS for an external web program called Pterodactyl and when i went to access the site where i needed to go to their admin panel it showed

502 Bad Gateway
nginx/1.12.1 (Ubuntu)

Steps i did:
nginx -t

OUTPUT:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

then i restarted the vps
after it booted i did service nginx status
output:

root@HSH-VPS:~# service nginx status
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
   Active: active (running) since Mon 2018-07-02 01:14:51 UTC; 21min ago
     Docs: man:nginx(8)
  Process: 1631 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 -
  Process: 1644 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
  Process: 1632 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
 Main PID: 1646 (nginx)
    Tasks: 3 (limit: 4915)
   Memory: 4.0M
      CPU: 61ms
   CGroup: /system.slice/nginx.service
           ├─1646 nginx: master process /usr/sbin/nginx -g daemon on; master_pro
           ├─1647 nginx: worker process
           └─1648 nginx: worker process

Jul 02 01:14:51 HSH-VPS systemd[1]: Starting A high performance web server and a
Jul 02 01:14:51 HSH-VPS systemd[1]: Started A high performance web server and a

then i restarted nginx and again with the 502 error
now when pterodactyl installs it creates and enables HTTPS for the ip address/the domain you assigned so i thought maybe if i add a firewall and allow port 443 and allowed https but that didn't solve it any ideas?

1 Answer

Your output log shows that nginx has a valid config file, and is running OK.

In this scenario, a 502 Error often means the web server (nginx) could handle and respond to the request just fine, but the application (pterodactyl, running via PHP-FPM) is broken or not properly configured and not connectable from nginx.

Look at the nginx error logs (based on pterodactyl documentation, they'll be here: /var/log/nginx/pterodactyl.app-error.log if you don't find anything there, try the default nginx error logs at /var/log/nginx/error.log

Any clues in that log?

Also - I wouldn't recommend ONLY allowing port 443 via firewall, because users who try and go to the non-secure http version of your url's won't get redirected to HTTPS, they'll just get an error. So ideally you want to allow ports 80 and 443

Have another answer? Share your knowledge.