OpenProject – 502 Bad Gateway with default TCP port 6000 – FIX How to fix the 502 - Bad Gateway HTTP error reported by NGINX while trying to connect to a default OpenProject instance by changing the default proxy port (TCP 6000)

OpenProject - 502 Bad Gateway with default TCP port 6000 - FIX

If you’re reading this it most likely means that you’re desperately looking for a way to fix the 502 – Bad Gateway error (or other similar errors) you’re receiving by NGINX while trying to connect to your brand-new OpenProject installation. Am I  right? If the answer is positive, keep reading.

As you might already know, the 502 – Bad Gateway error is often emitted by NGINX whenever it has to deal with requests that he cannot process, and can mean a number of different things: for this very reason, the best thing to do when you read it is to look inside the NGINX error log files (in CentOS, /var/log/nginx/error.log) where you will find the actual error in extended format. In most scenarios, you’ll find something like this:

[error] upstream prematurely closed connection while reading response header from upstream

If you find something like that, and you’re trying to connect to OpenProject using the default address 127.0.0.1:6000, it most likely means that… such port is busy! Yes, you heard it right: there’s a high chance that you’re not dealing with OpenProject, by with another service that is using the TCP port 6000… such as X11, which uses TCP port 6000 by default to allow connections between an X client and server over the network (most CentOS 7.x distributions have it enabled by default).

From what we’ve experienced, it definitely seems that OpenProject is not smart enough to notice that his port is busy, therefore it starts without giving any relevant signs… except being entirely unable to work, since its HTTP proxy listens to TCP port 6000 by default and is therefore cut out. This basically means that when we get the 502 – Bad Gateway resulting from the “upstream prematurely closed” error above, our browser is sending our requests to the wrong service – which isn’t made to deal with any HTTP call.

Luckily enough, deal with such issue is rather easy… you’ll just have to change the OpenProject proxy’s default TCP port – and, needless to say, change your NGINX configuration accordingly.

Here’s how you can do that in a nutshell.

Change OpenProject Proxy default port (TCP 6000)

  • Open a terminal window.
  • Type openproject run env to print all the OpenProject’s environment variables.
  • Check out the PORT value (it will most likely be 6000).
  • Type sudo openproject config:set PORT=6060 (or any other free TCP port you might want to use).

If you don’t know what replacement TCP port you should use, type netstat -antu to take a look at the busy ones: just be sure to pick a non-listed TCP port.

Change NGINX Configuration

If you’re experiencing this problem you should have a OpenProject’s NGINX configuration pointing to 127.0.0.1:6000, such as the following one:

Change any line containing 127.0.0.1:6000 with 127.0.0.1:6060 (or the replacement TCP port previously chosen).

If you did everything correctly, now your OpenProject default page should appear in all of its glory!

OpenProject - 502 Bad Gateway with default TCP port 6000 - FIX

That’s it: happy project management!

This post is part of a series of articles, tutorials and guides on the NGINX web server & reverse proxy. To read the other posts, click here!

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.