Outbound Proxy

If you are syncing RStudio Package Manager to create your own CRAN repository (see the CRAN source section), the server will need access to the internet to download manifest and package data. If you need to use an outbound proxy server, RStudio Package Manager uses the Proxy.URL configuration option to set the HTTP and HTTPS proxy behavior. For example:

; /etc/rstudio-pm/rstudio-pm.gcfg
[Proxy]
URL = 127.0.0.1:80

RStudio Package Manager does require that the proxy is enabled to perform SSL forwarding.

Running with a Proxy

If you are running RStudio Package Manager 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 Package Manager. This section describes how to correctly configure a reverse proxy with Nginx or Apache HTTPD.

When RStudio Package Manager is behind a proxy, it is important to send the original request URL information to RStudio Package Manager so that it can generate fully qualified URLs and return them the requester. For this reason, when proxying to RStudio Package Manager, we recommend adding a header, X-RSPM-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://rspm.company.com/some/path)

Some proxies (like Amazon Web Services Elastic Load Balancer), do not make it possible to add custom headers. Because of this, if this header is not supplied, "best efforts" are made utilizing the standard headers X-Forwarded-Proto, X-Forwarded-Host, and X-Forwarded-Port to parse the original request URL. If your proxy removes a server prefix from the path, X-Forwarded headers will not work for your use case, and you should use X-RSPM-Request. If both X-RSPM-Request and X-Forwarded headers are supplied, X-RSPM-Request takes precedence.

Using a Proxy for TLS/SSL

See the secure proxy section for information on configuring a proxy to handle HTTPS requests.

Nginx Configuration

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

apt-get install nginx

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

yum install nginx

On openSUSE/SLES, you can install Nginx using the following command:

sudo zypper install nginx

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

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    server {
        listen 80;
        location / {
            proxy_set_header    X-RSPM-Request $scheme://$host:$server_port$request_uri;
            proxy_pass http://localhost:4242;
        }
    }
}

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

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }
    server {
        listen 80;
        location /rspm/ {
            rewrite ^/rspm/(.*)$ /$1 break;
            proxy_set_header    X-RSPM-Request $scheme://$host:$server_port$request_uri;
            proxy_pass http://localhost:4242;
            proxy_redirect / /rspm/;
        }
    }
}

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

On systemd systems (Red Hat/CentOS 7-8, openSUSE/SLES, Ubuntu 16.04+):

systemctl restart nginx

On Upstart systems (Red Hat 6):

restart nginx

Apache Configuration

The Apache HTTPD server can act as a front-end proxy to RStudio Package Manager by first enabling three modules:

a2enmod rewrite
a2enmod headers
a2enmod proxy_http

The following configuration will permit proxying to RStudio Package Manager from the :3737 port. Depending on the layout of your Apache installation, you may need the Listen and VirtualHost directives in different files.

Listen 3737

<VirtualHost *:3737>
    RewriteEngine on
    RequestHeader set X-RSPM-Request "%{REQUEST_SCHEME}s://%{HTTP_HOST}s%{REQUEST_URI}s"
    ProxyPass / http://172.17.0.1:4242/
    ProxyPassReverse / http://172.17.0.1:4242/
</VirtualHost>

You can serve RStudio Package Manager from a custom path (e.g. /rspm) with a configuration like the following:

Listen 3737

<VirtualHost *:3737>
    RewriteEngine on
    RedirectMatch ^/rspm$ /rspm/
    RequestHeader set X-RSPM-Request "%{REQUEST_SCHEME}s://%{HTTP_HOST}s%{REQUEST_URI}s"
    ProxyPass /rspm/ http://172.17.0.1:4242/
    ProxyPassReverse /rspm/ http://172.17.0.1:4242/
    Header edit Location ^/ /rspm/
</VirtualHost>