Nginx 502: Bad Gateway with rstudio server

Hi I’m trying to set up RStudio server with a reverse proxy.

Here is my Nginx config

  • Postfix in Docker container can't resolve MX unless it gets restarted once
  • openshift origin v0.3.3 error starting docker registry pod on centos 6.6
  • SSH agent forwarding during docker build
  • Parameters to pass to docker run automatically on startup
  • Traefik : Let's Encrypt + other certificate
  • Docker compose and ansible: site.yml does not appear to be a file
  • user nginx;
    worker_processes 1;
    
    # Defines a file that will store the process ID of the main process.
    pid /var/run/nginx.pid;
    
    events {
      # Sets the maximum number of simultaneous connections that can be opened by a worker process.
      worker_connections 1024;
    }
    
    http {
      server {
    
        # Running port
        listen 80;
    
        # Proxying the connections
        location /rstudio/ {
          rewrite ^/rstudio/(.*)$ /$1 break;
          proxy_pass http://localhost:8787;
          proxy_redirect http://localhost:8787/ $scheme://$host/rstudio/;
        }
      }
    }
    

    Unfortunately I get a 502: Bad Gateway error. Do you have any idea?
    8787 is open as reported from netstat

    tcp6       0      0 :::80                   :::*                    LISTEN      -
    tcp6       0      0 :::8787                 :::*                    LISTEN      -
    

    RStudio and nginx is running on two separated docker container which have port opened

  • NFS or mounting shares with docker
  • how to make docker client connect to docker daemon over http
  • Too many docker mounts
  • Pull a local image to run a pod in Kubernetes
  • Cannot stop a cloudera/quickstart in Docker
  • What is equivalent remote api command to 'docker run -d'?
  • One Solution collect form web for “Nginx 502: Bad Gateway with rstudio server”

    There is a how-to documentation on the Rstudio website that details how to use either Nginx or Apache reverse proxies.

    https://support.rstudio.com/hc/en-us/articles/200552326-Running-RStudio-Server-with-a-Proxy

    For nginx it suggests the following configuration :-

    http {
    
    map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
    }
    
    server {
      listen 80;
    
    
      location /rstudio/ {
        rewrite ^/rstudio/(.*)$ /$1 break;
        proxy_pass http://localhost:8787;
        proxy_redirect http://localhost:8787/ $scheme://$host/rstudio/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 20d;
      }
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.