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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
server { listen 80; server_name SERVER_DOMAIN_NAME; root /opt/openproject/public; location ~ / { proxy_pass_request_headers on; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_set_header X-Forwarded-Server $host:$server_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:6000; } } |
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!
That's it: happy project management!