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

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


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?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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/ 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