Support

Running RStudio Connect with a Proxy

Follow

Note: this article is on configuring RStudio Connect to run behind a proxy. If you have a proxy set up to control access to your RStudio Connect server and are having issues installing packages, see our article here.

If you are running RStudio Connect behind a proxy server, you need to be sure to configure the proxy server so that it correctly handles all traffic to and from RStudio Connect. This section describes how to correctly configure a reverse proxy with Nginx.

When RStudio Connect is behind a proxy, it is important that we send the original request URL information to Connect so that it can generate FQDN URLs and return them the requester. For this reason, when proxying to Connect, we must add a header, X-RSC-Request, to the request. This header value should be the absolute URL of the original request made by the user or browser (i.e. https://connect.company.com/some/path)

Nginx Configuration

On Ubuntu, a version of Nginx that supports reverse-proxying can be installed using the following command:

sudo apt-get install nginx

On RedHat/CentOS, you can install Nginx using the following command:

sudo yum install nginx

To enable an instance of Nginx running on the same server to act as a front-end proxy to RStudio Connect you would add commands like the following to your nginx.conf file. This configuration assumes RStudio Connect is running on the same host as Nginx and listening for HTTP requests on the:3939 port. If you are proxying to RStudio Connect on a different machine or port, replace thelocalhost:3939 references with the correct address of the server where RStudio Connect is hosted.

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    server {
        listen 80;
    
        location / {
            proxy_set_header    X-RSC-Request $scheme://$host:$server_port$request_uri;
            proxy_pass http://localhost:3939;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_http_version 1.1;
        }
    }
}

If you want to serve RStudio Connect from a custom path (e.g. /rstudio) you would edit your nginx.conf file as shown below:

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    server {
        listen 80;

        location /rstudio/ {
            rewrite ^/rstudio/(.*)$ /$1 break;
            proxy_set_header    X-RSC-Request $scheme://$host:$server_port$request_uri;
            proxy_pass http://localhost:3939;
            proxy_redirect / /rstudio/;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_http_version 1.1;
        }
    }
}

After adding these entries you'll then need to restart Nginx so that the proxy settings take effect:

sudo /etc/init.d/nginx restart
Have more questions? Submit a request

Comments

Powered by Zendesk