Search code examples
nginxproxyrhel

502 error bad gateway with nginx on a server behind corporate proxy


I'm trying to install a custom service to one of our corporae server (those kind of server that are not connected to internet, unless all the trafic passes to a corporate proxy).

This proxy has been setup with the classic export http_proxy=blablabla in the .bashrc file, among other things.

Now the interesting part. I'm trying to configure nginx to redirect all traffic from server_name to local url localhost:3000

Here is the basic configuration I use. Nothing too tricky.

server {
  listen 443 ssl;
  ssl_certificate /crt.crt;
  ssl_certificate_key /key.key;
  server_name x.y.z;
  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass &http_upgrade;
  }
}
  • When I try to access the server_name, from my browser, I get a 502 error (a nginx error, so the requests hits my server).

  • When I try to access the local url curl --noproxy '*' https://localhost:3000, from the server, it is working. (I have to write the --noproxy '*' flag because of the export http_proxy=blablabla setup in the .bashrc file. If i do not write this, the localhost reuquest is send to our distant proxy, resulting the requet to fail)

My guess is that this is has to be related to the corporate proxy configuration, but I might been missleading.

Do you have any insights that you could share with me about this?

Thanks a lot !

  • PS: the issue is not related to any kind of SSL configuration, this part is working great
  • PS2: I'm not a sysadmin, all these issuses are confusing
  • PS3: the server I'm working on is a RHEL 7.9

Solution

  • It has nothing to do with proxy, found my solution here : https://stackoverflow.com/a/24830777/4991067

    Thanks anyway